Primary key value after insertion of row in SQL Server 2005

后端 未结 2 1397
抹茶落季
抹茶落季 2021-01-21 02:10

In SQL Server 2005 I am inserting a row into a table using a stored procedure and I want to fetch the new primary key value just after inserting that row. I am using following

2条回答
  •  一向
    一向 (楼主)
    2021-01-21 02:59

    If you have an Identity column as primary key you should use SCOPE_IDENTITY()

    You could also use the OUTPUT Clause to return the ID.

    insert into tableTest(testUserEmail,testUserName) 
    output inserted.ID
    values (@testValue, @testName)
    

提交回复
热议问题