If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > additional n00b questions regarding PKs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-09, 23:26
rbfree rbfree is offline
Registered User
 
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.
Reply With Quote
  #2 (permalink)  
Old 02-09-09, 23:52
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
and one more

Should all tables have primary keys the same length?
Reply With Quote
  #3 (permalink)  
Old 02-09-09, 23:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 02-09-09, 23:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by rbfree
Should all tables have primary keys the same length?
absotively not!!

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-10-09, 10:31
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
thanks again!

Thanks again Rudy,

It's all starting to settle into my dense old brain.
Reply With Quote
  #6 (permalink)  
Old 02-11-09, 22:13
rbfree rbfree is offline
Registered User
 
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?
Reply With Quote
  #7 (permalink)  
Old 02-11-09, 22:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 02-11-09, 23:58
rbfree rbfree is offline
Registered User
 
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On