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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I search and Entire datebase for Duplicate PK ?

Status
Not open for further replies.

CluelessJon

IS-IT--Management
Aug 11, 2003
158
GB
I have a database that is transfering data to another database.

I am unsure of the mapping so I cannot directly find the right table to seach for the primary key duplication

Is the a query can run on the database/ or tables to detect all Primary key duplicates

Thanks

Regards

Jonno BrainDump Specialist
MCSE(NT) MCSA(2k) CCNA
 
Hi Jon

Your primary key constraint should not allow any dublicates in you primary key field. But just in case I'm not understanding your question . . .

--Query to display dublicates in a given field
--Scripted copied from Tek-Tips.com
SELECT FLD1, count(1)
FROM TBL1
GROUP BY FLD1
HAVING count(1)>1

Matt
 
My first suggestion is that you become sure of the mapping from one database to the other. No one should ever try to work on a database (from a programming perspective)if they don't understand it's relationships. You can do way too much damage through ignorance.

As mdp said, priomary keys do not allow duplicates, so I presume you are trying to import data and it is telling you taht there is a duplicate inthe original table? In this case the error message should tell you what the problem is. What error are you getting?

 
Thanks for your Replys.

Yes the primary keys should not allow duplicates, but in this instance one has been created by a 3rd part application.

I am not sure about the mapping which is why I am looking for such a procedure to scan the entire set of tables.



Regards

Jonno BrainDump Specialist
MCSE(NT) MCSA(2k) CCNA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top