Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Updating a relational database via an asp
Message
De
04/06/2003 08:39:14
 
 
À
04/06/2003 04:18:45
Philip Jones
Cornwall County Council
Truro, Royaume Uni
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
00795654
Message ID:
00796099
Vues:
16
If you're using IDENTITYs to generate your PKs, you can use the SCOPE_IDENTITY() function to return the identity value that was assigned. You will find that this approach works best when you use a stored procedure to do the insert.
CREATE PROCEDURE usp_saveaddress 
 @addressid int OUTPUT
 ,@ ... -- parameters for address info
AS
INSERT INTO myaddresstable (...) VALUES (@...)
-- error handling omitted

SET @addressid = SCOPE_IDENTITY()
-Mike

>No, I'll try and explain.
>Say I put an address in an address table. The primary key value for that record will be generated automatically by sql server when I insert the other values.
>Next I want to add some personal details to say a person table. One of those details will be a foreign key value for the record in the address table.
>This will be the value that was automatically generated when I inserted my record into the address table.
>So to get the foreign key value for the address I'll have to go back and read it from the address table.
>
>How can I be sure that the I am reading the correct record? I could go to the bottom of the address table but what if someone else was adding details, via another asp form, at the same time.
>
>In short..
>If I add a record to a table.
>How can I get the primary key value of the record that I added and be absolutely sure that it is correct?
>
>
>Hope this is a better explaination.
>
>
>Phil.
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform