Results 1 to 2 of 2

Thread: Foreign Key will not work. Code provided.

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Red face Foreign Key will not work. Code provided.

    I've got several tables made but i need to link two tables together with pk & fk.

    The two tables are:

    CREATE TABLE Game_Play
    (GameNo SMALLINT,
    DatePlayed DATE,
    MethodologyType VARCHAR(50),
    No_of_SDLC_Iterations SMALLINT,
    No_of_Players SMALLINT,
    CONSTRAINT gameplay_pk PRIMARY KEY (GameNo));

    CREATE TABLE Player
    (PlayerID VARCHAR(5),
    PlayerName VARCHAR(50),
    CONSTRAINT player_pk PRIMARY KEY (PlayerID));

    I am trying to make playerid from the player table link to a field in the game_play table called playerid_winner as a foreign key.

    i am using oracle sql*plus.

    i have tried to add a new field and create the fk with the below

    ALTER TABLE GAME_PLAY ADD CONSTRAINT PLAYERID_WINNER
    FOREIGN KEY (PlayerID) REFERENCES PLAYER(PlayerID);

    and i have this error appear

    FOREIGN KEY (player_pk) REFERENCES PLAYER(PLAYER_PK)
    *
    ERROR at line 2:
    ORA-00904: "PLAYER_PK": invalid identifier

    Any ideas?

  2. #2
    Join Date
    Jun 2012
    Posts
    2
    I don't see a playerID column in your game_play table. That's probably the problem.

Posting Permissions

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