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
If you have an Identity column as primary key you should use SCOPE_IDENTITY()
SCOPE_IDENTITY()
You could also use the OUTPUT Clause to return the ID.
insert into tableTest(testUserEmail,testUserName) output inserted.ID values (@testValue, @testName)