在phpmyadmin上插入触发器

时间:2014-07-25 16:33:20

标签: mysql tsql phpmyadmin mysql-workbench

我是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$$;

1 个答案:

答案 0 :(得分:0)

  1. 通常首先创建表格
  2. 更改phpmyadmin界面中的默认分隔符[它位于您输入查询的文本框下]
  3. 单独运行create trigger脚本,不需要更改分隔符 因此,您的触发器代码不应包含delimiter $$;
相关问题