【发布时间】:2014-09-17 13:59:57
【问题描述】:
我是 MySQL 新手。我有两个表帖子和通知。我正在尝试为帖子中添加的每个新行创建一个触发器,我想将该新行添加到 notification_id。 它在 mysql 上正常工作,但在 phpmyadmin 触发器中不会执行,它给出了一个错误
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以了解正确的语法使用
第 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$$;
【问题讨论】:
-
所以要清楚,您已经创建了触发器,当您从 MySQL 执行 INSERT 时,它可以正常工作,但是从 phpMyAdmin 执行相同的 INSERT 失败并显示错误消息?您是通过“插入”选项卡插入还是直接输入 SQL?
标签: mysql tsql phpmyadmin mysql-workbench