标签:
建表语句:
CREATE TABLE googs( id INT(12) auto_increment PRIMARY KEY, gname VARCHAR(12), gprice DOUBLE ); CREATE TABLE googs_temp( id INT(12) auto_increment PRIMARY KEY, gname VARCHAR(12), gprice DOUBLE );
新建触发器:
create trigger tri_stu_delete BEFORE DELETE on googs for each row begin INSERT INTO googs_temp(id,gname,gprice) SELECT id,gname,gprice FROM googs WHERE id=old.id; end;
删除触发器:
DROP TRIGGER tri_stu_delete;
当执行以下语句时,触发器会被触发而自动执行相关操作:
INSERT INTO googs(id,gname,gprice) VALUES(3,‘aha‘,23); DELETE FROM googs WHERE id=3;
标签:
原文地址:http://www.cnblogs.com/mada0/p/4744685.html