标签:table tab int into test ble key 删除 var
触发器:当操作了某张表时,同时触发一些动作或行为。
例如:当向员工表插入一条记录时,希望同时向日志中插入数据
员工表:employee, 日志表:test_log
test_log脚本 CREATE TABLE test_log( id INT PRIMARY KEY AUTO_INCREMENT, content varchar(200) ); --创建触发器(增加) CREATE TRIGGER tri_empAdd AFTER INSET ON employee FOR EACH ROW --当向员工表插入一条数据时 INSERT INTO test_log (content) values(‘员工表插入了一条记录‘); --整个触发器的意思是:当我向员工表人插入一条数据时,日志表也插入一条数据。 --创建触发器(修改) CREATE TRIGGER tri_empAdd AFTER UPDATE ON employee FOR EACH ROW INSERT INTO test_log (content) values(‘员工表修改了一条记录‘); UPDATE employee SET empName=‘‘eric" WHERE eid=7; --创建触发器(删除) CREATE TRIGGER tri_empAdd AFTER DELETE ON employee FOR EACH ROW INSERT INTO test_log (content) values(‘员工表修改了一条记录‘); DELETE FROM employee WHERE eid = 7;
标签:table tab int into test ble key 删除 var
原文地址:http://www.cnblogs.com/StanLong/p/6883720.html