带有 Sequel Pro 的 MySQL 触发器

标签 mysql sql triggers

这是我第一次尝试使用触发器,我只是快速做了一些测试,但它给我一个错误。这是我的触发器(为插入后设置)

IF NEW.controller = 'index' THEN
    SET @controller = 'index';
ELSE
    SET @controller = 'other';
END IF;

INSERT INTO 'logs'
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

我收到以下错误:

MySQL said: 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 'INSERT INTO 'logs' ( staff_id, table_name, table_id, controller ) VALUES ( NEW' at line 7

怎么了?

最佳答案

你可以试试这个(只需从表名中删除引号):

INSERT INTO logs
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

或者你可以使用反引号

INSERT INTO `logs`
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

关于带有 Sequel Pro 的 MySQL 触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20503726/

相关文章:

mysql - Dockerfile 不从我的 initialize.sql 创建表

mysql - like 在 mySql 子查询中不起作用

MySql:选择两个特定值之间的行:

SQL Server - 在带有文本和数字的 varchar 字段中的两个数字范围之间进行选择

c# - 如何在同一个 .aspx 页面上使用两个更新面板

mysql - 在 mysql 查询中查找最接近指定日期时间的日期时间

mysql - 如何从远程服务器备份我的sql

java - 使用 Spring JPA 查询从序列中获取 nextval

tsql - 对于 TSQL 插入/更新触发器,插入和删除都可以为空吗?

mysql - 如何在更新之前触发 MYSQL 删除条目