@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT [sql server 2005]

前端 未结 2 1289
情话喂你
情话喂你 2021-01-25 00:39

Which should i use to get last inserted record id in sql server 2005?

I searched stackoverflow and i found this,

SQL: How to get the id of values I just INSERTed

2条回答
  •  走了就别回头了
    2021-01-25 00:58

    Triggers

    Using @@identity is reliant on the fact that there are no triggers in your database creating records elsewhere.

    If you create a record but a trigger then creates a log entry for the creation, @@identity will return you the id of the log entry in the log table.

提交回复
热议问题