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

后端 未结 26 2374
-上瘾入骨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条回答
  •  生来不讨喜
    2020-11-27 10:08

    I just had to do this and this was my manual solution:

    1. In phpmyadmin, check the row you wish to copy
    2. At the bottom under query result operations click 'Export'
    3. On the next page check 'Save as file' then click 'Go'
    4. Open the exported file with a text editor, find the value of the primary field and change it to something unique.
    5. Back in phpmyadmin click on the 'Import' tab, locate the file to import .sql file under browse, click 'Go' and the duplicate row should be inserted.

    If you don't know what the PRIMARY field is, look back at your phpmyadmin page, click on the 'Structure' tab and at the bottom of the page under 'Indexes' it will show you which 'Field' has a 'Keyname' value 'PRIMARY'.

    Kind of a long way around, but if you don't want to deal with markup and just need to duplicate a single row there you go.

提交回复
热议问题