Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Location
    Toronto
    Posts
    3

    Unanswered: '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!

  2. #2
    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.

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    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)
    )

Posting Permissions

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