Hi Team,
Need your help understanding Oracle DB's philosophy in the following code.
What purpose does the "ON DELETE SET NULL" serve here?
Code:CREATE TABLE IF NOT EXISTS t1(
c1 NUMBER,
c2 VARCHAR2(255),
CONSTRAINT pkey_t1
PRIMARY KEY(c1)
);
CREATE TABLE IF NOT EXISTS t2(
c1 NUMBER NOT NULL, -- Why does not Oracle complain about this
c2 VARCHAR2(255),
CONSTRAINT fkey_t2
FOREIGN KEY(c1)
REFERENCES t1(c1)
ON DELETE SET NULL --+ or this?
);
INSERT INTO t1 VALUES(1000,'Referenced-Record-1');
INSERT INTO t2 VALUES(1000,'Referencing-Record-1');
DELETE FROM t1 WHERE c1 = 1000;
Output of the DELETE statement:SQL Error: ORA-01407: cannot update ("T2"."C1") to NULL
01407. 00000 - "cannot update (%s) to NULL"
Note: I have tested the same functionality on MySQL and it clearly complains about it -
"Column 'c1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL".
Shouldn't Oracle also tell something similar?