看板 Database 關於我們 聯絡資訊
※ 引述《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