如何在MySQL中编写具有多个条件的触发器 [英] how to write trigger with multiple condition in mysql

查看:150
本文介绍了如何在MySQL中编写具有多个条件的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用以下字段制作了两个表:

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"

每当采样表字段 statussample 更改时,我想更新 status .条件应该是

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`)

该怎么办?我一直坚持使用..new来触发格式

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

推荐答案

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;

这篇关于如何在MySQL中编写具有多个条件的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆