Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Cleanup of child records...
I would propose one more solution:
delete from <child_table>
where rowid in
( select <child_table>.rowid from <child_table> minus select <child_table>.rowid from <child_table>, <parent_table> where <child_table>.<fk_field> = <parent_table>.<fk_field> )
In some cases it may be faster. But it's strongly recommended to have <fk_field> indexed on both tables.
Michael Rosenblum,
DBA. Dulcian, Inc.
-----Original Message-----
Bill
Sent: Thursday, June 13, 2002 1:30 PM
To: Multiple recipients of list ORACLE-L
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-----
Sent: Thursday, June 13, 2002 12:59 PM
To: Multiple recipients of list ORACLE-L
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.
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Michael Rosenblum INET: mrosenblum_at_dulcian.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-LReceived on Thu Jun 13 2002 - 19:28:07 CDT
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
![]() |
![]() |