SQl foreign key disabling

Advertisements

Is there a way i can declare a disabled foreign key in the table creation in SQL

i don’t want to do it by altering the table if possible.

>Solution :

From the CONSTRAINT documentation, use the DISABLE keyword:

CREATE TABLE table1 (
  ID NUMBER PRIMARY KEY
)

CREATE TABLE table2 (
  OTHER_ID CONSTRAINT table2__other_id__fk REFERENCES table1 (id) DISABLE
);

fiddle

Leave a ReplyCancel reply