In MySQL, can I copy one row to insert into the same table?

后端 未结 26 2294
-上瘾入骨i
-上瘾入骨i 2020-11-27 09:56
insert into table select * from table where primarykey=1

I just want to copy one row to insert into the same table (i.e., I want to duplicate an ex

26条回答
  •  -上瘾入骨i
    2020-11-27 10:26

    For a very simple solution, you could use PHPMyAdmin to export the row as a CSV file then simply import the amended CSV file. Editing the ID/primarykey column to show a 0 for the primarykey value before you import it.

    SELECT * FROM table where primarykey=1
    

    Then at the bottom of the page:

    Where is says "Export" simply export, then edit the csv file to remove the primarykey value, so it's empty, and then just import it into the database, a new primarykey will be assigned on import.

提交回复
热议问题