Results 1 to 2 of 2

Thread: FK PK relations

  1. #1
    Join Date
    Nov 2003
    Posts
    7

    Unanswered: FK PK relations

    Hi All,

    I have one query...
    I have composite primary key on two columns ....say on table XYZ...

    can i have one of this column as foreign key column for which values should be validated from other tables column...

    Can i define the column as FK which is already defined in another composite PK.

    How i should do this.....


    Thanks in advance

    Bhushan Sawant

  2. #2
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    534
    example:

    CREATE TABLE xyz (col1 SERIAL, col2 INT);

    CREATE UNIQUE INDEX xyz_pk ON xyz(col1,col2);

    ALTER TABLE xyz ADD CONSTRAINT (PRIMARY KEY (col1,col2) CONSTRAINT xyz_pk);

    ALTER TABLE xyz ADD CONSTRAINT (FOREIGN KEY (col2) REFERENCES other_table CONSTRAINT xyz_fk1);


    The value of the foreign key must (in this case) exist in the primary key constraint of table other_table.
    rws

Posting Permissions

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