我有一个名为ul_logins的表和一个名为userbase和userchanges的表.我知道,想要每当我从ul_logins删除一些用户时,就触发一个自动从userbase和userchanges中删除同一用户的触发器.用户的ID是ul_logins的ID,用户ID是userbase和userchanges的ID
我已经在mysql(phpmyadmin)中编写了此触发器
CREATE OR REPLACE TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM userbase WHERE userID = :old.id;
END
但这不起作用,我一直都出错.但我只是找不到问题所在
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near ‘TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM us’ at line 1
我已经用谷歌搜索,还有另一种解决方案并尝试了
DELIMITER |
CREATE OR REPLACE TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM userbase WHERE userID = :old.id;
END;|
DELIMITER ;
但这并不能正常工作.有什么建议么?
解决方法:
这应该是正确的语法:
DROP TRIGGER IF EXISTS deleteUser;
DELIMITER |
CREATE TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM userbase WHERE userID = old.id;
END;
|
DELIMITER ;