Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: ON DELETE SET NULL ??

RE: ON DELETE SET NULL ??

From: Jacques Kilchoer <Jacques.Kilchoer_at_quest.com>
Date: Mon, 19 May 2003 11:32:06 -0800
Message-ID: <F001.0059CD8B.20030519113206@fatcity.com>


> -----Original Message-----
> From: Janet Linsy [mailto:janetlinsy_at_yahoo.com]
>
> I used Erwin 3.5.2 to generate script. The DDL has
> the following, what exactly is ON DELETE SET NULL
> part?
>
> ALTER TABLE ED_RECORDINGS_PAYMENTS
> ADD FOREIGN KEY (RECORDING_ID)
> REFERENCES ED_RECORDINGS
> ON DELETE SET NULL;
Without the "on delete set null", you cannot delete a row in the parent table if the values are present in the child table. With the "on delete set null", you will be able to delete the rows in the parent table and the corresponding foreign key columns in the child table will be set to null.
If you had "on delete cascade" then the corresponding rows in the child table will be deleted along with the rows in the parent table. Example:
SQL> create table parent (n number primary key) ; Table creee.

SQL> create table child

  2     (n number, v varchar2 (20),
  3      foreign key (n) references parent (n) on delete set null) ;
Table creee.

SQL> insert into parent (n) values (1) ; 1 ligne creee.
SQL> insert into parent (n) values (2) ; 1 ligne creee.

SQL> insert into child (n, v) values (1, 'ONE') ; 1 ligne creee.
SQL> insert into child (n, v) values (2, 'TWO') ; 1 ligne creee.

SQL> delete from parent where n = 1 ;
1 ligne supprimee.

SQL> select * from child ;

        N V

--------- --------------------
          ONE
        2 TWO

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Jacques Kilchoer
  INET: Jacques.Kilchoer_at_quest.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon May 19 2003 - 14:32:06 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US