SQL - INSERT and catch the id auto-increment value

前端 未结 7 937
梦毁少年i
梦毁少年i 2020-12-05 19:26

What is the best way to get the auto-id value in the same SQL with a SELECT?

A forum said adding this \"; has Return Scope_Identity()\"
in the end

相关标签:
7条回答
  • 2020-12-05 19:57

    In SQL Server a insert using the select statement can have an output clause which will return the identity value and whatever other columns you might need to identify which identity goes to which record. If you are using a values clause, then use select scope_identity () immediately after the insert.

    0 讨论(0)
提交回复
热议问题