Cascade delete oracle database

background

  Associate relationships between the tables. In the main table or delete the master table data when received from the table and restrictions from the table data can not be deleted operation is complete.

Based on the drop cascade delete

   1 drop the Table of the main table name Cascade constraint A - 1, 2 Delete, delete the main table from the table foreign key column 

Based on the cascade delete delete

  When construction of the table, added on cascade constraint of the foreign key columns behind  

. 1    Create  Table LG ( - husband Table 
2  
. 3      lgid Number ( 10 ) Primary  Key ,
 . 4  
. 5      lgname VARCHAR2 ( 20 is ) Not  null 
. 6  
. 7    );
 . 8  
. 9    Create  Table LP ( - wife Table 
10  
. 11      LPID Number ( 10 ) Primary  Key ,
 12 is  
13 is      lpName VARCHAR2 ( 20 is) Not  null ,
 14  
15      lgid VARCHAR2 ( 20 ) the References LG (lgid) ON  the Delete   Cascade  UNIQUE  - 1: 1 relationship established + delete cascade delete pre-treatment 
16  
17    )

 

  Insert data 

    

. 1  INSERT  INTO LG values ( 1001 , ' Bob ' );
 2  INSERT  INTO LP values ( . 1 , ' red ' , 1001 )

 

  Lg tables and data insertion is completed lp a data table wherein each table record lp lg points recorded in the table

    

  Test results delete cascading delete 

    . 1 Delete from LG WHERE lgid = 1001 -. 1, deleting records from a table (Table LP) associated with 2, main table to delete the user lgid 1001 

    

Guess you like

Origin www.cnblogs.com/xuchuang/p/11866872.html