How to add a new column with foreign key constraint in a single statement in oracle

Tom Sebastian picture Tom Sebastian · Jul 18, 2013 · Viewed 38.2k times · Source

How to add a new column with foreign key constraint in a single statement in oracle?Can any one give an example query?

Answer

schurik picture schurik · Jul 18, 2013
    alter table tab1
    add c1 number(20) constraint tab1_c1_fk references tab2(c2);

c1 new column in the table tab1 with the FK tab1_c1_fk on the table tab2 column c2.