mysql 执行begin end_mysql触发器_begin end 执行多次语句

//多SQL中导出的触发器语句:

DROP TRIGGER IF EXISTS `t_trig`;

DELIMITER //

CREATE TRIGGER `t_trig` BEFORE INSERT ON `t_goods`

FOR EACH ROW beginset NEW.add_date = current_date();INSERT INTO test2 SET a2 = NEW.id;end

//

DELIMITER ;

/************************************************

************************************************

************************************************/

//在删除一个终端调研时触发删除销售体验和竞品分析

DELIMITER //

CREATE TRIGGER`delete_assistant_research` BEFORE DELETE ON `tb_assistant_research`

FOR EACH ROW begin

DELETE FROM `tb_assistant_experience` WHERE `research_id` = old.id;

DELETE FROM `tb_assistant_compete_analyse` WHERE `research_id` = old.id;

end

//

DELIMITER;

/************************************************

************************************************

************************************************/

//在删除一个竞品商品时, 删除该竞品商品的竞品分析数据

DELIMITER

CREATE TRIGGER `delete_product` AFTER DELETE ON`tb_assistant_compete_product`

FOR EACH ROW begin

DELETE FROM `tb_assistant_compete_analyse` WHERE `product_id` = old.id;

end

DELIMITER;

/************************************************

************************************************

************************************************/

//在删除某一家门店时,删除该门店的巡店和终端调研

//本地服务器118所需要的触发器语句

DROP TRIGGER IF EXISTS `delete_assistant_store`;

DELIMITER //

CREATE TRIGGER`delete_assistant_store` AFTER DELETE ON `tb_assistant_store`

FOR EACH ROW begin

DELETE FROM `tb_assistant_visitstore` WHERE `store_id` = old.id;

DELETE FROM `tb_assistant_research` WHERE `store_id` = old.id;

end

//

DELIMITER;

远程服务器:121.199.167.212所导出的触发器

DROP TRIGGER IF EXISTS `delete_assistant_store`//

CREATE TRIGGER `delete_assistant_store` AFTER DELETE ON `tb_assistant_store`

FOR EACH ROW begin

DELETE FROM `tb_assistant_visitstore` WHERE `store_id` = old.id;

DELETE FROM `tb_assistant_research` WHERE `store_id` = old.id;

end

//

/************************************************

************************************************

************************************************/

在删除某一个流程时,需要删除对应该流程的备注信息

sign=1删除巡店 sign=2删除销售体验 sign=3删除竞品分析

//以后用标准格式

DROP TRIGGER IF EXISTS `delete_assistant_option`;

delimiter //

CREATE TRIGGER`delete_assistant_option` AFTER DELETE ON `tb_assistant_option`

FOR EACH ROW BEGIN

IF old.sign=1 THEN

DELETE FROM `tb_assistant_visitstore_message` WHERE `option_id` = old.id;

ELSEIF old.sign=2 THEN

DELETE FROM `tb_assistant_experience_message` WHERE `option_id` = old.id;

ELSEIF old.sign=3 THEN

DELETE FROM `tb_assistant_compete_analyse_message` WHERE `option_id` = old.id;

END IF;

END;

//

delimiter ;

标准格式,版主给的

delimiter //

CREATE TRIGGER testref BEFORE INSERT ON test1

FOR EACH ROW BEGIN

INSERT INTO test2 SET a2 = NEW.a1;

DELETE FROM test3 WHERE a3 = NEW.a1;

UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;

END;

//

delimiter ;

原文:http://www.cnblogs.com/xiangxiaodong/p/3929061.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值