Title: Cleanup of child records...
delete from <child_table> where <fk_field> not in
(select <pk_field> from <parent_table>);
 
or
 
delete from <child_table> where not exists
(select <pk_field> from <parent_table>
where <parent_table>.<pk_field> = <child_table>.<fk_field>);
 
not exists usually out performs not in, but both will work
 
bill
 
-----Original Message-----
From: Richard Huntley [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 13, 2002 12:59 PM
To: Multiple recipients of list ORACLE-L
Subject: Cleanup of child records...

TIA List,

What is the most efficient way to remove child records from a table
that have no parent records in it's parent table. I want to build a FK,
to keep this from happening, but I need to do some cleanup first.


Reply via email to