作者ruby0104 (:))
看板Database
标题[SQL ] Trigger
时间Fri Apr 17 08:57:24 2009
最近刚开始用 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
1F:推 grence:呃..纯就资料表设计来看,计算可得的栏位通常不另外存 04/17 10:24