Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008

    Unanswered: Primary and foreign key on the same column

    Can both primary and foreign key constraints exist on the single column of a table? E.g. Suppose there is a database DB1 with tables A and B. Now, is it fine to apply a primary key constraint on the column A1 of the table A and foreign key on the same column that references the primary key of table B?

  2. #2
    Join Date
    Mar 2007
    Are you unable to try it yourself?
    SQL> create table tt1( c1 integer, constraint tt1_pk primary key (c1) );
    Table created.
    SQL> create table tt2( c1 integer, constraint tt2_pk primary key (c1),
      2    constraint tt2_fk foreign key (c1) references tt1 (c1) );
    Table created.
    So the answers are:
    Yes (when the design is fine).

Posting Permissions

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