Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    70

    Unanswered: Do Primary Keys Have To Be Unique?

    is it ok for primary keys to be the same across tables (i.e. can the primary keys of "Clients" be 1-2-3-4... and the primary keys of "Staff" to also be 1-2-3-4...)?
    or do they have to be completely unique throughout the database (i.e. "Staff" has s1-s2-s3-s4... and "Clients" has c1-c2-c3-c4...)?

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    There's no reason that primary keys can't be identical in different tables. BUT be sure you don't make a join betwen any two tables on the basis of their primary keys.

    The primary key of 'Staff' would appear in 'Clients' as a foreign key, and vice versa. Ergo, if you need to join the tables, you would join primary key of table 'X' with foreign key of table 'Y'.

    Sam

  3. #3
    Join Date
    May 2005
    Posts
    119
    They can be the same. I would suggest using a PK auto-numbering scheme; but also a second "soft key" that would have something a little more readable, like a userid that you can identify easily in a query as your database grows.

  4. #4
    Join Date
    Aug 2012
    Posts
    70
    Thanks for your help Sam

  5. #5
    Join Date
    Aug 2012
    Posts
    70
    Thank you Krista too

Posting Permissions

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