Copy row but with new id

后端 未结 6 1029
有刺的猬
有刺的猬 2020-12-07 22:36

I have a table \"test\" with an auto incremented id and an arbitrary number of columns.

I want to make a copy of a row in this table with all columns th

6条回答
  •  半阙折子戏
    2020-12-07 23:07

    depending on how many columns there are, you could just name the columns, sans the ID, and manually add an ID or, if it's in your table, a secondary ID (sid):

    insert into PROG(date, level, Percent, sid) select date, level, Percent, 55 from PROG where sid = 31 Here, if sid 31 has more than one resultant row, all of them will be copied over to sid 55 and your auto iDs will still get auto-generated. for ID only: insert into PROG(date, level, Percent, ID) select date, level, Percent, 55 from PROG where ID = 31 where 55 is the next available ID in the table and ID 31 is the one you want to copy.

提交回复
热议问题