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: SQL to insert only new records

Re: SQL to insert only new records

From: Pierre Bar <_pierre.bar_at_tractebel.be_>
Date: 1997/05/06
Message-ID: <01bc59e3$aa8f5660$b103018e@pc4496>#1/1

You can try something like this :
INSERT INTO table2
  SELECT field1, field2, field3
    FROM table1 a
  WHERE NOT EXISTS (SELECT *
     FROM table2
   WHERE field1 = a.field1

        AND field2 = a.field2)
Not necessary faster but clearer.

John Stathakis <jlstath_at_mail.icon.co.za> wrote in article <336DC9E2.6948_at_mail.icon.co.za>...
> Hello everyone,
>
> Here is a SQL statement I wrote to insert records from one table into
> another. The catch is that it ignores records that are already there, so
> you never have a duplicate primary key failure.
>
> Does this statement bypass the indexes, causing performance problems ?
>
> INSERT INTO table2
> SELECT a.field1, a.field2, a.field3 FROM
> table1 a, table2 b
> WHERE
> b.field1(+) = a.field1 AND
> b.field2(+) = a.field2 AND
> b.field1 is null AND
> b.field2 is null;
>
> Regards,
> John
>
  Received on Tue May 06 1997 - 00:00:00 CDT

Original text of this message

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