错误1442:无法更新存储的函数/触发器中的表

时间:2013-09-27 02:31:34

标签: mysql sql mysql-error-1442

我正在尝试更新第三方应用程序中的数据库。以下是受影响的两个表的架构:

Table 'camera' 
columns:  deviceID, connectionState

Table 'cameraRecording' 
columns: deviceID, recordToVolumeID 

我已尝试过这两个查询,但收到同样的错误。

mysql> update cameraRecording 
       SET recordToVolumeID='STRING' 
       WHERE deviceID 
       IN (select deviceID from camera WHERE connectionState=1);

ERROR 1442 (HY000): Can't update table 'camera' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

mysql> update cameraRecording a 
       JOIN camera b 
       ON a.deviceID=b.deviceID AND b.connectionState=1 
       SET recordToVolumeID='STRING';

ERROR 1442 (HY000): Can't update table 'camera' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

我不是SQL的专家,不经常使用它,但我很确定这应该有效。我猜测应用程序已经设置了触发器或功能......有没有办法执行此任务?我已经阅读了其他许多错误的帖子,但大多数人都试图创建一个触发器。

1 个答案:

答案 0 :(得分:2)

你能声明一个变量然后使用值吗?

DECLARE @id int;
SELECT @id = deviceID from camera WHERE connectionState=1;

update cameraRecording 
SET recordToVolumeID='STRING' 
WHERE deviceID = @id;