How to get the currently inserted row identity through query in sqlserver ?
how to get the currently inserted row identity through query in sqlserver ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vilas GitePosted Jul 4, 2011, 7:06 AM
if your using SQL Server 2005, let's use @@identity.
------------------------------------------------------
USE tour;
GO
--Display the value of tour_name in the last row in the table.
SELECT MAX(tour_name) FROM tourtbl;
GO
INSERT INTO tourtbl (tour_name,min_people,max_people,unit_price)
VALUES ('UK','5','5','25000');
GO
SELECT @@IDENTITY AS 'Identity';
GO
--Display the value of tour_name of the newly inserted row.
SELECT MAX(tour_name) FROM tourtbl;
GO
----------------------------------------------------------------------------
Amit ChoudharyPosted Jul 4, 2011, 6:20 AM
Thanks.