How do you copy a record in a SQL table but swap out the unique id of the new row?

前端 未结 11 553
猫巷女王i
猫巷女王i 2020-11-30 19:09

This question comes close to what I need, but my scenario is slightly different. The source table and destination table are the same and the primary key is a uniqueidentifie

11条回答
  •  情歌与酒
    2020-11-30 19:23

    Try this:

    
    insert into MyTable(field1, field2, id_backup)
        select field1, field2, uniqueId from MyTable where uniqueId = @Id;
    

    Any fields not specified should receive their default value (which is usually NULL when not defined).

提交回复
热议问题