-- ***********************触发器************************--
-- 新建一张日志表
CREATE table test_log(
id INT PRIMARY KEY AUTO_INCREMENT,
content VARCHAR(100)
)
-- 添加员工的同时,向日志表插入一条添加记录
-- 触发器,是在执行了触发的动作,才会执行的
-- 添加触发器
CREATE TRIGGER tri_empAdd AFTER INSERT ON ssh_employee FOR EACH ROW
INSERT INTO test_log(content) VALUES('员工表插入了一条记录');
INSERT INTO ssh_employee VALUES ('1', 'loger', 'wsw@qq.com', '2015-12-29 00:00:00', '2016-01-08 14:03:24', '2', '1000.00', '200.00', '上海');
SELECT * FROM test_log;
-- 更新触发器
CREATE TRIGGER tri_empupadate AFTER UPDATE ON ssh_employee FOR EACH ROW
INSERT INTO test_log(content) VALUES('更新了一条员工信息');
UPDATE ssh_employee set LAST_NAME='废物' WHERE ID=1;
SELECT * FROM test_log;
-- 删除触发器
CREATE TRIGGER tri_empDelete AFTER DELETE ON ssh_employee FOR EACH ROW
INSERT INTO test_log(content) VALUES('删除了一条员工信息');
DELETE FROM ssh_employee WHERE id=12;
SELECT * FROM test_log;
mysql数据库触发器(六)
最新推荐文章于 2024-09-06 21:00:16 发布