Removing duplicates records in SQL Server table

  In this example we are going to remove some duplicate records from the sql server table.
  According to below screen shot few records has been duplicated.
image
By executig below script you can remove the duplicate records.
--Insert distinct records to temporary table
select distinct * into #temp From [dbo].[Products]
--delete all records from [dbo].[Products]
delete from [dbo].[Products]
--insert distinct records from temp table to [dbo].[Products]
insert into [dbo].[Products]             
select * from #temp
--drop the temp table
drop table #temp
--output you can see
select * from [dbo].[Products]
image
Removing duplicates records in SQL Server table Removing duplicates records in SQL Server table Reviewed by Pubudu Dewagama on 12:26:00 AM Rating: 5

No comments: