Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Violation of PRIMARY KEY constraint

Status
Not open for further replies.

Dabase

Programmer
Apr 2, 2004
122
PT
Hi,

I am trying to INSERT data to MyTable using a SELECT statement from another table, I am getting the following error:

Server: Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK_MyTable'. Cannot insert duplicate key in object 'MyTable'.
The statement has been terminated.

Is there a way of identifying the duplicate records at the source table?



Thanks
Dabase
 
Yup. All possibilities:

a) source table has one dupe, target table has another one
b) source table has all dupes, target table has no dupes
c) a) + b)

You can check a) with INNER JOIN query, and b) with classic GROUP BY/HAVING COUNT(*) > 1 query.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top