Mysql 触发器
Posted cd ~/Homestead
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql 触发器相关的知识,希望对你有一定的参考价值。
insert_trigger
BEGIN
if(NEW.id not in (select sourceid from site_newsall where catid = NEW.catid and sourceid = NEW.id ))then
insert into table1 (value1,value2,value3)
values (NEW.value1,NEW.value2,NEW.value3);
end if;
END
update_trigger
BEGIN
if(NEW.id not in (select sourceid from site_newsall where catid = NEW.catid and sourceid = NEW.id )) then
insert into table1 (value1,value2,value3)
values (NEW.value1,NEW.value2,NEW.value3);
ELSE
UPDATE table1 SET value1=NEW.value1,value2=NEW.value2,value3=NEW.value3 where id=NEW.ID;
end if;
END
delete_trigger
BEGIN
if( OLD.id in (select id from table1 where id = OLD.id ))
then
DELETE FROM table1 where id=OLD.id;
end if;
END
以上是关于Mysql 触发器的主要内容,如果未能解决你的问题,请参考以下文章