Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - adding foreign constraint in disabled state?

Tags:

sql

oracle

I need to add a foreign key constraint but initially it should be disabled. I can add it in create table sentence or in an alter table sentence, it does not matter. I do not know the reason behind this request (it may be ORA-02298: cannot validate (BLA.BLA_FK) - parent keys not found ) but I was asked to do it this way. So what is the correct sentence for this in Oracle database?

like image 466
mcvkr Avatar asked Dec 18 '22 07:12

mcvkr


1 Answers

You'd want to do something like

ALTER TABLE YOUR_TABLE
  ADD CONSTRAINT YOUR_TABLE_FK1
    FOREIGN KEY (COLUMN1, COLUMN2) REFERENCES SOME_OTHER_TABLE (COLUMN1, COLUMN2)
      DISABLE
      NOVALIDATE;
like image 99