只是一个简单的问题,毫无疑问,有人会知道答案。
我需要能够在触发器中进行多次插入/更新。每次尝试都以失败告终:(
DROP TRIGGER IF EXISTS `Insert_Article`// CREATE TRIGGER `Insert_Article` AFTER INSERT ON `Article` FOR EACH ROW insert into FullTextStore (`Table`, `PrimaryKey`, `ColumnName`, `Data`, `Created`) values ('Article', NEW.ArticleID, 'Description', NEW.Description, UNIX_TIMESTAMP()) //
目前,上面的代码只是在插入父表时在表中插入一行。这很好。
为了使它与多种价值观一起工作,我需要做
DROP TRIGGER IF EXISTS `Insert_Article`// CREATE TRIGGER `Insert_Article` AFTER INSERT ON `Article` FOR EACH ROW insert into FullTextStore (`Table`, `PrimaryKey`, `ColumnName`, `Data`, `Created`) select 'Article', NEW.ArticleID, 'Description', NEW.Description, UNIX_TIMESTAMP() union select 'Article', NEW.ArticleID, 'Keywords', NEW.Keywords, UNIX_TIMESTAMP() //
但是…一定有更简单的方法吗?当我尝试使用; 终止每个语句,它失败并带有
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near 'select 'Article', NEW.ArticleID, 'Keywords', 'NEW.Keywords, UNIX_TIMESTAMP())' at line 1
我什至无法使多个更新语句起作用。
如果有人可以指出我在做什么错,那将是很大的帮助?
干杯
加文
从文档: 创建触发器语法
trigger_stmt是触发触发器时要执行的语句。如果要执行多个语句,请使用BEGIN … END复合语句构造。这也使您能够使用存储例程中允许的相同语句
CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BEGIN INSERT INTO test2 SET a2 = NEW.a1; DELETE FROM test3 WHERE a3 = NEW.a1; UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1; END;