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

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

WBOY
發布: 2016-06-06 09:33:27
原創
1322 人瀏覽過

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板