Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get the last identity value for a table?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01421835
Message ID:
01421846
Vues:
35
>>>It's not the last value in the IDENTITY column but the last IDENTITY value generated for a specified table. To get the last value in the column you'll have to run a query with MAX() on that column.
>>
>>I get it. I only use IDENTITY for a PK column so in my case I have only one IDENTITY per table. In this case doing MAX() on the column and IDENT_CURRENT would give the same result, right?
>
>It may not. The next IDENTITY value is generated outside of any transaction. If the transaction that causes next value to be generated is rolled back than that value will not make it in the table.

I see. Then, if I use MAX() and the table is large (say 100,000 rows), will SQL take a second (or maybe several) to calculate the max value of the column? (btw, the syntax is "MAX('MyColumnName')", right?)
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform