删除SQL表中重复的数据

来源:互联网 发布:qt tcp客户端接收数据 编辑:程序博客网 时间:2024/05/17 22:04


第一步:将表中的数据放到一个临时表里面

Select Identity(Int, 1, 1)  As id,
        * Into #temp
 From   DianPingPoi  dpp
 Where  dpp.DistrictId = 4313 And dpp.CuisineId = 210


第二步:删除临时表里面的重复数据  
 Delete #temp
 Where  id Not In (Select Max(id)
                   From   #temp
                   Group By
                        所有该表的列名)


第三步:删除表里面符合条件的数据                     
Delete from  DianPingPoi  Where DistrictId=4313 And CuisineId=116
 

第四步:将临时表里面的数据插入到表中
 Insert Into DianPingPoi
   (
   所有该表的列名
   )
 Select        所有该表的列名  From   #temp
 

第五步:删除临时表
 Drop table #temp


0 0
原创粉丝点击