Correct use of SCOPE_IDENTITY function within simple stored procedure

后端 未结 3 1858
野性不改
野性不改 2021-02-10 11:20

I\'d like to simply send some information from a simple client to a log file and then use the identity created for further processing.

Is the following use of SCOP

3条回答
  •  天命终不由人
    2021-02-10 11:52

    You can also use SCOPE_IDENTITY in two separate statements, such as:

    Assuming that the table has an identity field of course

    Insert into [ABCTable]
    ([A], [B])
    select 'WhateverA', 'WhateverB'
    

    Then use the function SCOPE_IDENTITY() in the Where clause, like:

    Update [ABCTable] Set [A] = 'UpdateA', [B] = 'UpdateB'
    Where IdentityField = SCOPE_IDENTITY()
    

    Thus, the scope_identity is a reliable link to the record just inserted.

提交回复
热议问题