Question : How can I delete duplicate records in a SQL database without a primary key?

Is there a way to delete duplicate entries on a SQL Server database that doesn't have a primary key? I can delete duplicate entries by using the SET ROWCOUNT command but this would take far too long as I would have to specify each and every record that has duplicates.  This won't do since the table has thousands of records.  Is there an easy way to delete all duplicates?  

Answer : How can I delete duplicate records in a SQL database without a primary key?

Dear

Say you have a table for example with the following field
col1,col2,col3,col4,colN.

first use the below command

Select * into Table1_Back from Table1

then use below command to truncate the orginal table

Trunacate table1

then use the below query to insert records back with possible duplicate records filtered .

insert into Table1 (fieldList)
Select distinct col1,col2,col3,col4,colN from Table1_back

for cross check of the above tricks first you run the 2 queries as below.

1) select count(*) from table1
2) Select distinct col1,col2,col3,col4,colN from Table1
and check how much the no of records returned by the 1(first) query Result, and how much no of rows returned by second query. you should defintly get the diffrent no of rows for both queries, and if so my above trciks will suly work for you.
i had the same problem in past where my database had a master table of mebers and child table of Member Tree , and i had used the above techinq and it works. I hope i should surly work for you.

Thanks & Regards.
Random Solutions  
 
programming4us programming4us