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