我制作了两张包含以下字段的表格:
TABLE 1: "demo"
FIELD: "demoid"
FIELD: "cpid"
FIELD: "status"
TABLE 2: "sample"
FIELD: "id"
FIELD: "conid"
FIELD: "statussample"
FIELD: "date"
每当示例表字段status
发生更改时,我想更新statussample
。
条件是
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`)
如何做到这一点?我坚持使用这个......更新为触发格式
答案 0 :(得分: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;