Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get PK after Insert
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Get PK after Insert
Divers
Thread ID:
01675696
Message ID:
01675696
Vues:
88
Hi,

I am sure I have done it before but forgot how to do it. In a Stored Procedure, the code Inserts a row into a table.
How do I get the PK (Identity) of the newly added row?
Also, is it after COMMIT or before?

TIA

UPDATE. I code I found is as follows (right after INSERT)
Set @NewPk = SCOPE_IDENTITY()
However, the stored procedure does two tables INSERT. If I do the SCOPE_IDENTITY() right after the table where I need the Identity, will it work?
Google shows two more approaches:
@@Identity.
Ident_Current()
But which one to choose?
"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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform