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

Finding Duplicates 1

Status
Not open for further replies.

fiber0pti

ISP
Nov 22, 2000
96
US
I have a field called customer ID. I want to make it a primary key but it says there are duplicates. How do I find these so I can delete one of them? There's abuot 4,000 records so I can't really look through them.
 
Hi,

Here is what I do to rid of dupes:

Create a table with same structure,
I do this with
select top 1 into temptab from maintable

truncate temptab

insert into temptab
(Customerid)
(select distinct customerid from maintable)

Update temptab
set temptab.field1=maintable.field1,
temptab.field2=maintable.field2
from temptab, maintable
where temptab.customerid=maintable.customerid

You can then rename the table to maintable.
Then set primary key.

I would keep the main table to make sure you did not remove any data you wanted to keep.

HTH, Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top