Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: orphaned records

Re: orphaned records

From: fumi <fumi_at_tpts5.seed.net.tw>
Date: 2000/04/13
Message-ID: <8d4qck$mli$2@news.seed.net.tw>#1/1

Dave Salvador <dsalvador_at_mail.walmar.com> wrote in message news:B518C079.160%dsalvador_at_mail.walmar.com...
> I have two tables, with the 2nd table having a foreign key relationship to
> the first. Could someone suggest a query that would allow me to find any
> orphaned records.
>
> Thanks

Two ways:

  1. Use an outer join, for example,

select e.*
  from emp e, dept d
  where e.deptno=d.deptno(+)
    and d.deptno is null;

2. Use the exceptions table:

alter table emp enable constraint fk_deptno exceptions into exceptions; select * from emp
  where rowid in (select row_id from exceptions where owner='SCOTT'     and table_name='EMP' and constraint='FK_DEPTNO'); Received on Thu Apr 13 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US