MySQL trigger to copy all field values to another table, how? [duplicate]

限于喜欢 提交于 2019-12-25 00:58:46

问题


I have 2 identical table (100% identical),

DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER `db`.`new_user` AFTER INSERT
ON `db`.`user`
FOR EACH ROW BEGIN
INSERT INTO db2.`users` COPY ALL INSERTED DATA
END$$

DELIMITER ;

How should the INSER query look like? Do I have to specifiy all field names one by one?


回答1:


Since NEW is not a row identifier but rather a syntactic way for referring to particular columns in a row being manipulated by a trigger, you need to specify column names

INSERT INTO db2.`users` VALUES(NEW.id, NEW.username, ...);


来源:https://stackoverflow.com/questions/15419227/mysql-trigger-to-copy-all-field-values-to-another-table-how

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!