This question already has answers here:
How to copy a row from one SQL Server table to another
                                
                                    (5个答案)
                                
                        
                                6年前关闭。
            
                    
我有两个相同的表(100%相同),

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 ;


INSER查询应如何显示?我必须一一指定所有字段名称吗?

最佳答案

由于NEW不是行标识符,而是引用由触发器操作的行中特定列的语法方式,因此需要指定列名

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

关于mysql - MySQL触发器将所有字段值复制到另一个表中,怎么办? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15419227/

10-09 21:17