0

尝试创建触发器以将行从一个表插入另一个表时出现语法错误...更新过程中的日期和时间。这是我的查询:

INSERT INTO `second_table` (field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12)
  (SELECT `field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8`, `field9` FROM `first_table` WHERE `field1` = NEW.`field1`), CURDATE(), NOW(), (SELECT `field12` FROM `second_table` WHERE `field1` = NEW.`field1`);

此触发器将在first_table更新时运行。我不确定这是否是完成任务的正确方法。为简单起见,我概括了字段和表名称。

编辑:

两个表之间的列是相同的。我只想更新触发发生的日期和时间。这有效,但显然只是复制了以前的日期和时间:

INSERT INTO `second_table` (SELECT * FROM `first_table` WHERE `field1` = NEW.`field1`);
4

1 回答 1

2

尝试:

INSERT INTO `second_table` (field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12)
 (SELECT `field1`, `field2`, `field3`, `field4`, `field5`, `field6`, `field7`, `field8`, `field9`, CURDATE() AS `field10`, NOW() AS `field11`, `field12` FROM `first_table` WHERE `field1` = NEW.`field1`);
于 2013-04-10T16:21:44.553 回答