我是 MySQL 新手。我有两个表帖子和通知。我正在尝试为帖子中添加的每个新行创建一个触发器,我会将该新行添加到 notification_id 中。 它在 mysql 上正常工作,但在 phpmyadmin 触发器中不会执行,它会给出错误
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 11
这是我的表格的样子:
帖子表
create table posts
(
id int,
topic_id tinyint,
post_creator int,
post_date datetime,
post_content text
);
通知表
create table notification
(
not_id int ,
top_id tinyint,
p_creator int,
p_date datetime,
p_content text
);
notification_id触发器
delimiter $$;
create trigger notification_id before Insert on posts
for each row
begin
declare id int;
declare topic_id int;
declare post_creator int;
declare post_date datetime;
declare post_content text;
insert into notification(not_id,top_id,p_creator,p_date,p_content) values(new.id,new.topic_id,new.post_creator,new.post_date,new.post_content);
end$$;
最佳答案
- 通常先创建表
- 更改 phpmyadmin 界面中的默认分隔符 [它位于您输入查询的文本框下方]
- 单独运行创建触发器脚本,不包含更改分隔符的行
因此,触发器的代码不应包含
delimiter $$;
关于mysql - 插入到 phpmyadmin 上的触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24960390/