how to write trigger with multiple condition in mysql

99封情书 提交于 2021-01-28 19:52:02

问题


I had made two tables with the following fields:

TABLE 1: "demo"
FIELD: "demoid"
FIELD: "cpid"
FIELD: "status"     


TABLE 2: "sample"
FIELD: "id"
FIELD: "conid"    
FIELD: "statussample"
FIELD: "date"

I want to update the status whenever the sample table field statussample gets changed. The condition would be

1) `demoid` and `id` would be same and `cpid` and `conid` would be same.(if more than one values comes i want the last inserted value of  `sample` using the field `date`)

How to do that?I had stuck with this..new to Trigger format


回答1:


DELIMITER //

CREATE TRIGGER sample_after_update
AFTER UPDATE
    ON sample FOR EACH ROW

BEGIN

   UPDATE demo
   SET demoid = NEW.id,
       cpid   = NEW.conid

END; //
DELIMITER;


来源:https://stackoverflow.com/questions/38745441/how-to-write-trigger-with-multiple-condition-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!