How to insert multiple records and get the identity value?

前端 未结 7 768
暗喜
暗喜 2020-11-27 03:54

I\'m inserting multiple records into a table A from another table B. Is there a way to get the identity value of table A record and update table b record with out doing a cu

7条回答
  •  情话喂你
    2020-11-27 04:24

    MBelly is right on the money - But then the trigger will always try and update table B even if that's not required (Because you're also inserting from table C?).

    Darren is also correct here, you can't get multiple identities back as a result set. Your options are using a cursor and taking the identity for each row you insert, or using Darren's approach of storing the identity before and after. So long as you know the increment of the identity this should work, so long as you make sure the table is locked for all three events.

    If it was me, and it wasn't time critical I'd go with a cursor.

提交回复
热议问题