Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2009
    Posts
    104

    additional n00b questions regarding PKs

    I have a table called operators. Each operator (operatorID) will have employees but the number will vary from 1 to n. So, my thinking is that I should create an employees table that includes all employees for all operators, using a compound key including operatorID and employeeID. Is that correct?

    Is there reason (if it's not a business rule) that one wouldn't want to lump all employees?

    Again, thanks.

  2. #2
    Join Date
    Feb 2009
    Posts
    104

    and one more

    Should all tables have primary keys the same length?

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    can an employee belong to more than one operator?

    if so, then you need a third table

    if not, then the PK of the employees table shouild be the employee id only, and the operator id would be a foreign key in that table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by rbfree
    Should all tables have primary keys the same length?
    absotively not!!

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2009
    Posts
    104

    thanks again!

    Thanks again Rudy,

    It's all starting to settle into my dense old brain.

  6. #6
    Join Date
    Feb 2009
    Posts
    104

    what considerations determine key field length?

    Am I right in thinking that primary keys are often constituted by tuples? In forestry, a standID value would commonly reference any number of attributes (dominant species, some structural trait, management objective, etc.). Is that fairly common?

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    is it common to create an arbitrary key to represent a sizable number of attributes, which in their aggregate are unique, rather than making them a composite primary key?

    yes

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Feb 2009
    Posts
    104

    interesting and thanks

    Wow, then you could run queries for semantic content using a numeric primary key. All very interesting. Thanks!

Posting Permissions

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