Results 1 to 2 of 2

Thread: Using the primary key for one to many relationship?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    1
    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

  2. #2
    Fanatic Member Bonker Gudd's Avatar
    Join Date
    Mar 2000
    Location
    Saturn
    Posts
    748
    Set a variable to @@IDENTITY straight after the insert and use that.
    You must declare it first!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width