Copy rows from the same table and update the ID column

前端 未结 8 439
情歌与酒
情歌与酒 2021-02-01 02:09

I have the following table

\"alt

I have inserted Product B to it and it gives me an ID of 15

8条回答
  •  北海茫月
    2021-02-01 03:04

    If your id is not autoincrement or declared sequence and if u dont want to create a temporary table:

    you can use:

    INSERT INTO Tabel1 SELECT ((ROW_NUMBER( ) OVER ( ORDER BY ID  )) + (SELECT  MAX(id) FROM Table1)) ,column2,coulmn3,'NewValue' FROM Tabel1 Where somecolumn='your value`
    

提交回复
热议问题