gpt4 book ai didi

mysql - 如何创建触发器以将新用户详细信息插入另一个表?

转载 作者:行者123 更新时间:2023-11-29 00:48:34 24 4
gpt4 key购买 nike

我正在尝试将外部论坛脚本 (SMF) 与我的网站“同步”。这意味着,当用户在我的网站上注册时,触发器会在外部论坛成员表中插入用户详细信息(用户名、密码和电子邮件)。类似的东西,但它是错误的,sql 错误。

CREATE TRIGGER forumReg 
AFTER INSERT ON hotaru_users
FOR EACH ROW
BEGIN
INSERT INTO forum_members (member_name, email_address, passwd)
VALUES (NEW.user_username, NEW.user_email, NEW.user_password);
END

hotaru_users 是我的网站用户表,forum_members 是外部论坛用户表,两个表都在同一个mysql数据库中

错误

Erro

consulta SQL:

CREATE TRIGGER forumReg AFTER INSERT ON hotaru_users
FOR EACH
ROW
BEGIN
INSERT INTO forum_members( member_name, email_address, passwd )
VALUES (
NEW.user_username, NEW.user_email, NEW.user_password
);

Mensagens do MySQL : Documentação
#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 '' at line 6

最佳答案

要么删除BEGINEND:

CREATE TRIGGER forumReg 
AFTER INSERT ON hotaru_users
FOR EACH ROW
INSERT INTO forum_members (member_name, email_address, passwd)
VALUES (NEW.user_username, NEW.user_email, NEW.user_password);

或者更改创建触发器的分隔符:

DELIMITER $$
CREATE TRIGGER forumReg
AFTER INSERT ON hotaru_users
FOR EACH ROW
BEGIN
INSERT INTO forum_members (member_name, email_address, passwd)
VALUES (NEW.user_username, NEW.user_email, NEW.user_password);
END
$$
DELIMITER ;

关于mysql - 如何创建触发器以将新用户详细信息插入另一个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9488412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com