标签:mit mysql sql 更新 int name 语法 end into
#触发器
#创建基本语法
#插入前
CREATE trigger tri_before_insert_tb1 BEFORE INSERT ON tb1 FOR EACH ROW
BEGIN
...
END
#插入后
CREATE TRIGGER tri_after_insert_tb1 AFTER INSERT ON tb1 FOR EACH ROW
BEGIN
...
END
#删除前
CREATE TRIGGER tri_before_delete_tb1 BEFORE DELETE tb1 FOR EACH ROW
BEGIN
...
END
#删除后
CREATE TRIGGER tri_after_delete_tb1 AFTER DELETE tb1 FOR EACH ROW
BEGIN
...
END
#更新前
CREATE TRIGGER tri_beofre_update_tb1 BEFORE UPDATE ON tb1 FOR EACH ROW
BEGIN
...
END
#更新后
CREATE TRIGGER tri_after_update_tb1 AFTER UPDATE ON tb1 FOR EACH ROW
BEGIN
...
END
#插入前触发器
delimiter //
CREATE TRIGGER tri_before_insert_tb1 BEFORE INSERT ON tb1 FOR EACH ROW
BEGIN
IF NEW.NAME == ‘alex‘ THEN
VAlUES
(‘aa‘)
END
END //
delimiter;
#插入后触发器
delimiter //
CREATE TRIGGER tri_before_insert_tb1 AFTER INSERT ON tb1 FOR EACH ROW
BEGIN
IF NEW.num = 666 THEN
INSERT INTO tb2 (NAME)
VAlUES
(‘666‘),
(‘666‘);
ELSE IF NEW.num = 555 THEN
INSERT INTO tb2 (NAME)
VAlUES
(‘555‘),
(‘555‘);
END IF;
END//
delimiter;
#删除触发器
DROP TRIGGER tri_after_insert_tb1;
#使用触发器
insert into tb1(num) values(666);
标签:mit mysql sql 更新 int name 语法 end into
原文地址:https://www.cnblogs.com/gerenboke/p/11766428.html