2013-09-27 103 views
1

我試圖在第三方應用程序中更新數據庫。這裏是受影響的兩個表的架構:錯誤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

http://stackoverflow.com/questions/1582683/mysql-trigger-stored-trigger-is-already-used-by-statement-which-invoked-stored-t?rq=1 – Mihai

回答

2

你可以聲明,然後一個變量使用值?

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

update cameraRecording 
SET recordToVolumeID='STRING' 
WHERE deviceID = @id; 
相關問題