Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting the last entry in identity column?
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01549403
Message ID:
01549404
Views:
32
>Hi,
>
>Do you think the following two approaches of getting the last entry in the identity column always give the same result?
>
>
>select IDENT_CURRENT( 'table_name' )
>
>
>
>select top 1 IdentColumn  from table_name group by IdentColumn order by IdentColumn desc
>
>
>And if yes, am I correct in assuming that the first method (using IDENT_CURRENT()) would be a faster way of getting the value?
>
>TIA.

The correct way is to use OUTPUT clause of the INSERT command. The second best method is to use SCOPE_IDENTITY() function. All other methods should not be used.

See this blog post
http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform