Monday, March 26, 2012

Duplicate key ignored !

Hi guys,

i have the following tables:

Table1:
[PKID] WITH INDEX "IGNORE DUPLICATE KEY"

Table2:
[FKID]

and i have the following SQL statement:

insert into Table1
select distinct FKID
from Table2
where FKID not in (select PKID from Table1)

The above SQL statement is in a DTS package which raises "Duplicate key ignored" error... i can't see how that can happen since i am already checking the key if it already exists. ..

Please help !!!

TNT :sDuplicates are probably in Table2.

Not that this has ever happened to me, but I read about it in this book once. ;)

-PatP|||Thanks for replying pat. :)

Duplicates are not selected from table2 since the 'distinct' keyword is used.

Very wierd problem... i don't have much hair left to pull out :s

T.|||Without having sample tables and data, it is tough (near impossible) to eliminate all of the possibilities. My guess is that you have non-duplicate values in table2 that become duplicates in table1 (this often happens due to type changes, etc).

If you can post the table definitions and some sample data, I'm certain that one of us can figure out your problem... Without them, all we can do is guess... Your description of the problem probably won't help us much.

-PatP|||Thanks for your response.
i will post some data when the problem occurs again.

Thanks again.
TNTsql

No comments:

Post a Comment