Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Foreign key on delete cascade tips

Oracle Tips by Burleson Consulting

January 6, 2011

Question:  Can you give me some tips on when to implement the "on delete cascade" vs. the "on delete restrict" feature of a foreign key constraint?

Answer: The choice between on delete restrict or on delete cascade depends on the design of your application.  You have three choices for managing deletes on Oracle foreign key constraints:

alter table sample1
   add foreign key (col1)
references
   sample (col2)
on delete no action;

alter table sample1
add foreign key (col1)
references
   sample (col2)
on delete restrict;

alter table sample1
add foreign key (col1)
   references sample (col2)
on delete cascade;

When you create a foreign key constraint, Oracle default to "on delete restrict" to ensure that a parent rows cannot be deleted while a child row still exists. 

However, you can also implement on delete cascade to delete all child rows when a parent row is deleted.

Using "on delete cascade" and "on delete restrict"  is used when a strict one-to-many relationship exists such that any "orphan" row violates the integrity of the data.

Also, see these important notes on foreign key indexing, especially important if you delete or update parent rows.

Many systems use "on delete cascade" when they have ad-hoc updates so that the end-user does not have to navigate the child table and delete dozens or hundreds of child entries.  Of course, using "on delete cascade" is dangerous because of possible mistakes and because issuing a single delete on a parent row might invoke thousands of deletes from the child table.

Obviously, if you are using "on delete cascade" and you do not create an index on the child parent key the deletion of a parent row would require a full-table scan of the child table, to find and delete the child rows.

 


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.


 

��  
 
 
 
 

 
 
 

 
 
Oracle performance tuning software 
 
oracle dba poster
Oracle Linux poster