首页 > 数据库 > mysql教程 > mysql 触发器插入数据可以,但是update没有成功,update前后的insert都执行了

mysql 触发器插入数据可以,但是update没有成功,update前后的insert都执行了

WBOY
发布: 2016-06-06 09:33:27
原创
1340 人浏览过

mysql

DROP TRIGGER IF EXISTS t_afterinsert_invitation_trigger ;
DELIMITER $$
CREATE TRIGGER t_afterinsert_invitation_trigger
AFTER INSERT ON invitation_trigger
FOR EACH ROW
BEGIN
declare _mid int;
declare _parent_level int;
declare _mids int;
declare _l int;
declare _r varchar(50);
set _mid = New.mid;
set _parent_level = New.midlevel;
set _mids = New.mids;

<code>INSERT INTO `test`.`invitation` (`id`, `mid`, `midlevel`, `mids`, `midslevel`) VALUES (New.id, _mid, _parent_level, _mids, New.midslevel);UPDATE invitation _up INNER JOIN (SELECT T2.midFROM (         SELECT             _r AS _mids,     (SELECT _r = mid FROM invitation WHERE mids = _mids) AS mid,     _l = _l + 1 AS lvl         FROM                 (SELECT _r = New.mid, _l = 0) vars,                 invitation h         WHERE _r  0) T1 JOIN invitation T2 ON T1._mids = T2.mids AND T2.midlevel > New.midlevelORDER BY T1.lvl ASC) BON _up.mid = B.midSET _up.midlevel = New.midlevel;INSERT INTO `test`.`invitation` (`id`, `mid`, `midlevel`, `mids`, `midslevel`) VALUES ('42', '14', '2', '43', '3');</code>
登录后复制

END$$
DELIMITER ;

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板