Home > MySQL > Copy MySQL row with new id

CREATE TEMPORARY TABLE tmp SELECT * from my_table WHERE ...;
ALTER TABLE tmp drop pk_id; # drop autoincrement field
INSERT INTO my_table SELECT 0,tmp.* FROM tmp;
DROP TEMPORARY TABLE tmp;

Reference: https://stackoverflow.com/questions/11331573/copy-row-but-with-new-id/11331672#11331672



Flag Counter