mysql – 创建触发器错误:语法无效
作者:互联网
SQL查询:
CREATE TRIGGER tg_newuser_insert
BEFORE INSERT ON tbl_newuser
FOR EACH ROW
BEGIN
INSERT INTO tbl_seq VALUES (NULL)
SET NEW.id = CONCAT('YTUM', LPAD(LAST_INSERT_ID(), 8, '00000'));
END
MySQL said: Documentation
#1064 – 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 ‘SET NEW.id = CONCAT(‘YTUM’, LPAD(LAST_INSERT_ID(), 8, ‘00000’));
END’ at line 6
解决方法:
您的格式设置已关闭,请记住DELIMITER $$语句是必需的,因为它与创建存储过程没有什么不同.
Check the documentation any time you run into issues like this.
滚动文档大约一半以查看示例.
但是,这就是你要找的东西:
DELIMITER $$
CREATE TRIGGER tg_newuser_insert
BEFORE UPDATE ON tbl_newuser
FOR EACH ROW
BEGIN
SET NEW.id = CONCAT('YTUM', LPAD(LAST_INSERT_ID(), 8, '00000'));
END $$
DELIMITER ;
标签:database-trigger,sql,mysql 来源: https://codeday.me/bug/20190928/1825597.html