Search This Blog

Wednesday, January 12, 2011

How do you delete duplicates rows from a table

1. copy the structure of base_temp into temp_table
select * into temp_table from base_temp where 1=2

2. create a unique index on the columns that contains the duplicate rows with the ignore_dup_key attribute .this may be more columns the key for the table.

Create unique index temp_idx on temp_table(col1,col2…..) with ignore_dup_key

3. Now insert base_table into temp_table
Insert temp_table select * from base_table
Truncate the base table and copy the data in temp_table to base_table

No comments:

Post a Comment