Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get PK after Insert
Message
 
 
À
14/08/2020 09:12:04
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01675696
Message ID:
01675748
Vues:
40
Yes, you are reading my message correctly, the SP inserts just one row.

And I did use OUTPUT somewhere in this project.

Thank you for your input.

>Just one comment...yes, SCOPE_IDENTITY works great, when you are inserting one row and therefore only expecting a single scalar value.
>
>And it sounds like, from what you were saying, your proc is designed to only insert one row.
>
>Just a note...SCOPE_IDENTITY isn't going to help much if you insert multiple rows in an insert statement. For that, the OUTPUT clause that Naomi and others suggested will give you the newly assigned identity-PK for "all" the newly inserted rows.
>
>The other nice thing about OUTPUT, as others mentioned - if you have calculated/default values in a table, OUTPUT will also allow you to get those as well. OUTPUT is SQL Server's way of saying, "here is what the full row(s) look like , after the INSERT is finished
>
>OUTPUT can seek like overkill if your proc is only geared towards one row - but just something to always be aware of.
"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
Répondre
Fil
Voir

Click here to load this message in the networking platform