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 > Database Server Software > DB2 > 'multiple' primary keys?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-18-04, 11:27
rprp rprp is offline
Registered User
 
Join Date: Oct 2004
Location: Toronto
Posts: 3
'multiple' primary keys?

Hi there,
I'm new to db2, sorry if this question sounds stupid.

I have a table:

CREATE TABLE Fielding_Stats(
pid INT REFERENCES Player(id) NOT NULL,
year INT(4) NOT NULL,
fielding_attempts INT(4) NOT NULL,
fielding_errors(4) NOT NULL
)

I cannot make the pid the primary key for this table because if a player plays for multiple years, he will have multiple entries in this table.

Is there a way I can 'combine' pid and year, as this would create a unique key.


Thanks!
Reply With Quote
  #2 (permalink)  
Old 10-18-04, 11:45
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
You can include multiple columns in your primary key. The approprate columns to include in the key will be dependent upon your design.
Reply With Quote
  #3 (permalink)  
Old 10-19-04, 02:57
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
CREATE TABLE Fielding_Stats(
pid INT REFERENCES Player(id) NOT NULL,
year INT(4) NOT NULL,
fielding_attempts INT(4) NOT NULL,
fielding_errors(4) NOT NULL,
primary key (pid, year)
)
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