Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / Table
 

ON DELETE CASCADE clause with a FOREIGN KEY constraint

ON DELETE CASCADE clause with a FOREIGN KEY constraint specifies that when a row in the parent table is deleted, any matching rows in the child table are also deleted. SQL> SQL> SQL> -- create demo table SQL> create table Customer(   2    id         NUMBER(3) primary key,   3    NAME       VARCHAR2(15 BYTE)   4  )   5  / Table created. SQL> SQL> create table account (   2    id         NUMBER(3),   3    type       VARCHAR2(20 BYTE)   4  )   5  / Table created. SQL> SQL> ALTER TABLE account   2  ADD CONSTRAINT fk   3  customerid REFERENCES customer(id) ON DELETE CASCADE; Table altered. SQL> SQL> drop table  account; Table dropped. SQL> SQL> drop table customer; Table dropped. SQL>