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

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

WBOY
Release: 2016-06-06 09:33:27
Original
1318 people have browsed it

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>
Copy after login

END$$
DELIMITER ;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template