Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inserting rows violating PK

Author  Topic 

musicweekdan
Starting Member

1 Post

Posted - 2002-05-27 : 09:52:29
Hi,

I am trying to run some large insert statements. Does anyone know if I can configure SQL to skip over inserting any rows that violate the tables primary key but continue inserting rows after that?

Thanks
Dan

Andy Verity
Starting Member

12 Posts

Posted - 2002-05-27 : 11:00:32
If each line is a straight Insert Into Values then you could put a go after each statement which would ensure that only those which are correct would run and it would not affect the rest.

This will not tell you however which lines caused the problems.

Go to Top of Page

dsdeming

479 Posts

Posted - 2002-05-28 : 08:06:22
How about using a where clause:

INSERT INTO targettable( columnlist )
SELECT columnlist FROM sourcetable WHERE pkcolumn not in(
SELECT pkcolumn FROM targettable )

Go to Top of Page

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-05-28 : 16:27:30
Note that this select will not eliminate PK dups from within "sourcetable". You might consider adding a DISTINCT to the outer select.

quote:

How about using a where clause:

INSERT INTO targettable( columnlist )
SELECT columnlist FROM sourcetable WHERE pkcolumn not in(
SELECT pkcolumn FROM targettable )





setBasedIsTheTruepath
<O>
Go to Top of Page
   

- Advertisement -