Showing posts with label skipping. Show all posts
Showing posts with label skipping. Show all posts

Friday, February 24, 2012

Inserting Records, Skipping Duplicates

I'd like to ask if there's any statement to insert records into a table, suc
h
that if any record violates the primary key constraint, it will "neglect" th
e
record and insert the next one.
Thank youAn exception/error will be generated if you try to insert a row that
violates the primary key constraint. You can pre-empt the primary key
constraint violation by checking each row on insert via trigger.
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:CC9F8302-1C4D-4141-B9B1-EADC999CC01B@.microsoft.com...
> I'd like to ask if there's any statement to insert records into a table,
> such
> that if any record violates the primary key constraint, it will "neglect"
> the
> record and insert the next one.
> Thank you|||Hi,
Maybe if you perform your inserts one row at a time within a loop you could
handle the errors with @.@.ERROR.
Ray
"wrytat" wrote:

> I'd like to ask if there's any statement to insert records into a table, s
uch
> that if any record violates the primary key constraint, it will "neglect"
the
> record and insert the next one.
> Thank you|||Add a WHERE NOT EXISTS() to the INSERT.
INSERT Whatever
VALUES('a', 'b', 'c')
WHERE NOT EXISTS
(select * from Whatever as X
where X.pk = 'a')
or
INSERT Whatever
SELECT A, B, C
FROM Somewhere
WHERE NOT EXISTS
(select * from Whatever as X
where X.pk = Somewhere.A)
Roy Harvey
Beacon Falls, CT
On Wed, 14 Jun 2006 19:30:02 -0700, wrytat
<wrytat@.discussions.microsoft.com> wrote:

>I'd like to ask if there's any statement to insert records into a table, su
ch
>that if any record violates the primary key constraint, it will "neglect" t
he
>record and insert the next one.
>Thank you