mysql触发器更新nex列: Syntax error

标签 mysql mariadb

我想要创建此触发器来为 clomn 设置默认值,但我收到此消息错误:#1064 - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在第 4 行 '' 附近使用的正确语法

这是我的脚本:

CREATE TRIGGER trg_set_content_val BEFORE INSERT
    ON post_table
    FOR EACH ROW BEGIN
        set NEW.content = 'mu value here';
END;

最佳答案

您需要设置delimiter存储程序前的分号以外的内容,然后将其改回来:

DELIMITER //
CREATE TRIGGER trg_set_content_val 

BEFORE INSERT
    ON post_table
    FOR EACH ROW BEGIN
        set NEW.content = 'mu value here';
END//
DELIMITER ;

原因:

If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.

To redefine the mysql delimiter, use the delimiter command. The following example shows how to do this for the dorepeat() procedure just shown. The delimiter is changed to // to enable the entire definition to be passed to the server as a single statement, and then restored to ; before invoking the procedure. This enables the ; delimiter used in the procedure body to be passed through to the server rather than being interpreted by mysql itself.

关于mysql触发器更新nex列: Syntax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42543843/

相关文章:

php - 这些读数对于大约 500 CCU 的应用来说合适吗?

docker - 无法更改在Docker中运行的数据库

MySQL tc.log 文件

php - 由于 wamp 上可能不正确的编码/解码,特殊字符未相应显示

Mysql - 根据值的出现进行排名

php - $_SESSION 已创建但 $_SERVER ['HTTP_COOKIE' 中没有 PHPSESSID]

mysql - 加速本地MySql对大表发起规范化查询

MySQL 1136 插入具有自动递增和默认字段的值时出错

mysql - sql从表中获取第N最高的工资

C++ 连接到 mysql/mariadb 非常慢