mysql 触发更新下一列:语法错误

mysql Trigger for update nex column : Syntax error

我想创建此触发器来为 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.