码迷,mamicode.com
首页 > 其他好文 > 详细

触发器

时间:2015-08-20 12:17:24      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:

建表语句:

技术分享
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
);
View Code

 

新建触发器:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!