Created
June 19, 2017 08:24
-
-
Save sokil/5c66a040889d5ba3cd2f86b499cfe46a to your computer and use it in GitHub Desktop.
Clone rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- create temporary table | |
| create temporary table cloned_rows_table like source_table; | |
| -- clone some tows to temporary table | |
| insert into cloned_rows_table select * from source_table where some_condition = 42; | |
| -- apply some data modifications to cloned_rows_table | |
| -- .... | |
| -- regenerate auto increment id | |
| SET @max = (select max(id) from source_table); | |
| update cloned_rows_table set id = @max:=@max+1; | |
| -- put cloned rows back to source table | |
| insert into source_table select * from cloned_rows_table; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment