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

前端 未结 11 547
猫巷女王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:36

    insert into MyTable (uniqueId, column1, column2, referencedUniqueId)
    select NewGuid(), // don't know this syntax, sorry
      column1,
      column2,
      uniqueId,
    from MyTable where uniqueId = @Id
    

提交回复
热议问题