作者Maisky (McDummy)
看板Database
标题Re: [SQL ] Trigger
时间Fri Apr 17 23:56:00 2009
※ 引述《ruby0104 (:))》之铭言:
: 最近刚开始用 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内不使用 SQL statement,而是直接在
更新前先做资料修改.
create trigger tr_cal_profit before update on tableA for each row
begin
if (new.itemID = old.itemID) then
set new.profit = new.SellPrice - old.Cost;
end if;
end;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 76.124.53.119