前几天查看数据库,发现有表有大量重复数据。
下面是去除重复数据的方法,不知道有没有更好的办法:
1、去除重复的最大ID
--t_CAR 表去重 delete t_car where car_id in( select max(car_id) from t_car where 1=1 group by car_num having count(1)>1 )
2、部分数据重复出现多次,执行1000次循环
declare @num int declare @end int set @num=0 set @end=1000 while @num<@end begin delete t_car where car_id in( select max(car_id) from t_car where 1=1 group by car_num having count(1)>1 ) set @num = @num+1 end
总结:方法比较笨,也实现了功能;不知道有没有更好的办法