[SQL ] Trigger
最近剛開始用 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
推
04/17 10:24, , 1F
04/17 10:24, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):