Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the last entry in identity column?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01549403
Message ID:
01549404
Vues:
33
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform