Forgot but.. how to get the last added record ID?

  • Thread starter Thread starter Edwin Knoppert
  • Start date Start date
E

Edwin Knoppert

Something with @Identity field or so... forgot.

Someone having copy of a SQL statement doing this?
 
Sericinus said:
select scope_identity()

SELECT TOP 1 'ID_field' FROM 'Table'
ORDER BY 'ID_field' DESC



Where 'ID_field' is the name of the Identity field you are after and
'Table' is the name of the table that identity field comes from
 
I'm using ASP.NET so in a multi-user environment this is impractical.
I even doubt the identity stuff can help me with this.
They speak about threading but all users are in the main thread pool (iis)
Since i open the db on masterpage load and free it on unload, i'm not sure
the connection is shared among users, never tested that aspect.

If shared the identity can fail imo.
 
There are three ways to retrieve the last identity value:
@@IDENTITY, IDENT_CURRENT() and SCOPE_IDENTITY(). They
behave differently exactly in respect to sharing sessions/tables.
Refer to BOL for more info.
 
Back
Top