mysql - 插入到 phpmyadmin 上的触发器

标签 mysql tsql phpmyadmin mysql-workbench

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

最佳答案

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

关于mysql - 插入到 phpmyadmin 上的触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24960390/

相关文章:

php - 如何在数据库中相应地保存 gmail 电子邮件

sql - Management Studio 中的结果集列宽

SQL Server : query columns to JSON object with group by

mysql - 二级开发人员使用 1&1 访问 phpMyAdmin

php - 将特定列导入 phpmyadmin 数据库

mysql - 2 个表之间的内部连接 ​​- 奇怪的语法?

mysql - 外键约束问题

sql - 使用外键,我可以在复合主键中引用固定值吗?

mysql - phpMyAdmin 错误代码 : 13 Can't get stat of './test'

java - 解析函数不起作用