Tom Sebastian
Tom Sebastian

Reputation: 3433

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

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

Upvotes: 35

Views: 58966

Answers (2)

schurik
schurik

Reputation: 7928

    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.

Upvotes: 75

Neeraj Gahlawat
Neeraj Gahlawat

Reputation: 1679

ALTER TABLE CODE_LIST_TYPE_ERROR 
ADD ID_CODE_LISTS VARCHAR2(50) NOT NULL
CONSTRAINT CODE_LIST_TYPE_ERROR_FK REFERENCES CODE_LISTS(ID);

oracle query to modify table and add new column which is refrence of another table

Upvotes: 13

Related Questions