PDA

Click to See Complete Forum and Search --> : Using the primary key for one to many relationship?


Peter Erhard
Mar 29th, 2000, 10:57 AM
Hi There!

When I save a new record in the database, I used before 'Select @@Identity' to retrieve the primary (or do I better call it unique index) of that freshly inserted record.
I then save some other record in a second table and save this unique index to create a one to many relationship.

Now I heart, its bad to rely on the value returned for @@Identity, because for an multiuser application. I can understand this perfectly.

But why should I not rely on this unique index to create my one to many relationship and what would be a better method?

Cheers,

Peter

Bonker Gudd
Mar 29th, 2000, 05:54 PM
Set a variable to @@IDENTITY straight after the insert and use that.
You must declare it first!
:D