我正在尝试将触发器设置为sql,以使用表c_p_r内的字段“ title”中的值更新gf的值,但是语法出现错误。有人可以指出我错了吗?
CREATE TRIGGER setgf
AFTER UPDATE ON c_p_r
FOR EACH ROW BEGIN
TRUNCATE gf
UPDATE gf
SET gf = title
FROM c_p_r
这件事正在回答我
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE gf
SET gf = title
FROM c_p_r' at line 5
有人可以指出我的错吗?
最佳答案
您的UPDATE
sql查询格式错误。另外,如果您尝试在更新过程中将一个字段值复制到另一字段。您应该使用BEFORE UPDATE处理程序。我会这样写查询:
CREATE TRIGGER setgf
BEFORE UPDATE ON c_p_r
FOR EACH ROW BEGIN
SET NEW.gf = COALESCE(NEW.gf, NEW.title); //this will take care of not overriding the gf if it was part of update statement
END