Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How delete records when foreign key constraint is involved

user9179120Nov 7 2011 — edited Nov 7 2011
Hi, I have 2 tables: A (with 3,000 records) and B (with 300,000,000 records). B has a foreign key constraint versus A.
If I execute "+delete from A where...+" it takes a long time to return (many hours), I think because Oracle checks integrity constraint from B to A via foreign key.
To reduce execution time of delete statement on A, I think this solution:
- first, I execute "+alter table B DISABLE constraint FK_VS_A+"
- then "+delete from A where...+"
- and in final "+alter table B enable novalidate constraint FK_VS_A+".
Is it correct ?
How many time requires re-enable constraint on B table with 300,000,000 records ? All actions must take few time as possible, so out of service is reduced.
I note that B table has been previously purged, so there are no records to point to deleted records in A table. Thanks for support. GP
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2011
Added on Nov 7 2011
4 comments
5,477 views