看板 Database 關於我們 聯絡資訊
最近剛開始用 Mysql... 想要建個 trigger 來自動更新 'Profit' tableA (itemID,SellPrice,Cost,Profit) create trigger tr_cal_profit after update on tableA for each row update tableA set profit=SellPrice-Cost where itemID=OLD.itemID; trigger可以建立, 但是每次update的時候,都會出現錯誤. "Can't update table 'tableA' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. 我可以理解, 是因為擔心造成迴圈的問題. 所以在trigger裏,不能update本身的table. 但是我記得MS SQL Server是可以這麼寫的. 所以我想問, SQLServer裏, 如果遇到迴圈這種情形,系統是怎麼自動避免的呢?! 另外, mysql 有類似 SQLServer if update() 的function 嗎? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 71.132.227.241
grence:呃..純就資料表設計來看,計算可得的欄位通常不另外存 04/17 10:24