今天小玩了一下MySQL触发器,很简单,具体工作中还没有使用过,这里写写加深记忆,呵呵
建表:
create table test1 (id int,name varchar(30));
create table test2 (id int,insert_count int,update_count int,delete_count);
创建触发器:
delimiter |
create trigger trigger_delete_count
after delete
on test1 for each row
begin
update test2 set delete_count=delete_count+1;
end
|
delimiter |
create trigger trigger_insert_count
after insert
on test1 for each row
begin
update test2 set insert_count=insert_count+1;
end
|
delimiter |
create trigger trigger_update_count
after update
on test1 for each row
begin
update test2 set update_count=update_count+1;
end
|
实现的功能,把test1表的insert,update,delete次数统计到test2表中
阅读(1082) | 评论(0) | 转发(0) |