gpt4 book ai didi

带有 Sequel Pro 的 MySQL 触发器

转载 作者:行者123 更新时间:2023-11-29 03:36:45 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com