Best way to get identity of inserted row?

后端 未结 14 2455
醉梦人生
醉梦人生 2020-11-21 07:06

What is the best way to get IDENTITY of inserted row?

I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY

14条回答
  •  后悔当初
    2020-11-21 07:48

    Add

    SELECT CAST(scope_identity() AS int);
    

    to the end of your insert sql statement, then

    NewId = command.ExecuteScalar()
    

    will retrieve it.

提交回复
热议问题