使用更新触发器来更新另一个表 [英] Using an update trigger to update another table
问题描述
我正在研究的程序的后端设计不佳,基本上需要两个不同的表来保存完全相同的信息.我正在尝试编写一个触发器,该触发器将使用与表A中刚刚更新的信息相同的信息来更新表B. 我不确定是否只是语法错误或缺少概念,将不胜感激……这是我到目前为止的一切
The program I am working on has a poorly designed backend and basically there are two different tables needed to hold the exact same information. I am trying to write a trigger that will update table B with the same information that was just updated in table A. Oh and this is using a MYSQL database I am not sure if I am just having a syntax error or if I am missing concepts, any help would be much appreciated... here is what I have as of yet
DELIMITER $$
DROP TRIGGER IF EXISTS after_update_A;
CREATE TRIGGER `after_update_A`
AFTER UPDATE ON `A` FOR EACH ROW
BEGIN
UPDATE TABLE B
SET username = NEW.username
, password = NEW.password
, email = NEW.email
WHERE id = NEW.id
END
$$
DELIMITER ;
我得到的错误都与此类似... 错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法以在'= users.username附近使用 ,B.email = users.email D'在第4行
And the errors I get are all some what similar to this... ERROR 1064 (42000): 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 '= users.username , B.email = users.email D' at line 4
推荐答案
您需要使用;
关闭触发器中的每个语句,我的意思是每个.
You need to close every statement inside the trigger with a ;
, and I do mean every.
CREATE TRIGGER `after_update_A` AFTER UPDATE ON `A` FOR EACH ROW
BEGIN
UPDATE TABLE B
SET username = NEW.username
, password = NEW.password
, email = NEW.email
WHERE id = NEW.id; //<<-----------
END $$
这篇关于使用更新触发器来更新另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!