问题
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