Home > Software design >  SQl foreign key disabling
SQl foreign key disabling

Time:11-04

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.

CodePudding user response:

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

  • Related