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
,@ ...
AS
INSERT INTO myaddresstable (...) VALUES (@...)
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.