Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Check to see if records exists

I am inserting massive amounts of data into a table using a insert stored
procedure. The problem is that i need to check whether the records i am adding
are already in the database.
I can use the IF EXISTS statement with a SELECT query in side it, however
i am worried that that this may take alot longer and also put more strain
on the server.
Are there any alternative ways of checking to see if records exist in the
database?

Cheers
Jerome
[483 byte] By [Jerome] at [2007-11-9 21:10:34]
# 1 Re: Check to see if records exists
something like:

INSERT table (cols...)
SELECT cols..
FROM otherTable o
WHERE NOT EXISTS ( SELECT 1
FROM table t
WHERE t.PK_id = o.PK_id )
--
HTH,
David Satz
Principal Web Engineer
Hyperion Solutions

"Jerome" <JMcKoylew@hotmail.com> wrote in message
news:3daeb5dc$1@tnews.web.dev-archive.com...
>
> I am inserting massive amounts of data into a table using a insert stored
> procedure. The problem is that i need to check whether the records i am
adding
> are already in the database.
> I can use the IF EXISTS statement with a SELECT query in side it, however
> i am worried that that this may take alot longer and also put more strain
> on the server.
> Are there any alternative ways of checking to see if records exist in the
> database?
>
> Cheers
> Jerome
David Satz at 2007-11-11 23:52:38 >