创建一个删除触发器 [英] Creating a delete trigger

查看:105
本文介绍了创建一个删除触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 ul_logins 的表,以及一个名为 userbase userchanges的表。我知道,想要的是,每当我从 ul_logins 删除一些用户时,就会触发一个触发器,自动从 userbase 用户更改。用户的ID是 id ,位于 ul_logins userID userbase userchanges

I have a table called ul_logins and a table called userbase and userchanges. I know, want, whenever I delete some user from ul_logins a trigger to automatically delete the same user from userbase and userchanges. The id of the user is id at ul_logins and userID at userbase and userchanges

在mysql中(phpmyadmin)

I have written this trigger in mysql (phpmyadmin)

CREATE OR REPLACE TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM userbase WHERE userID = :old.id;
END

但是它不起作用,我一直都出错。但是我只是找不到问题所在

But it doesn't work, I get an error all the time. But I just can't find what the problem is


#1064-您的SQL语法有错误;在第1行在'TRIGGER deleteUser之后在ul_logins
上删除ul_logins
对于每行开始
从我们这里删除

#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

我已经用Google搜索,还有另一种解决方案并尝试过

I already googled and there was another solution and tried this

DELIMITER |

CREATE OR REPLACE TRIGGER deleteUser AFTER DELETE ON ul_logins
FOR EACH ROW BEGIN
DELETE FROM userbase WHERE userID = :old.id;
END;|

DELIMITER ;

但这在所有情况下均无效。有建议吗?

but this didn't work neitehr. Any suggestions?

推荐答案

这应该是正确的语法:

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 ;

这篇关于创建一个删除触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆