1.查询不重复的数据存到临时表里,删除掉原表,然后将临时表的数据存到原表里,上代码:
- Select distinct * into Tmp from a
- Drop table a
- Select * into a from Tmp
- Drop table Tmp
Select distinct * into Tmp from a
Drop table a
Select * into a from Tmp
Drop table Tmp
2.当原表和其他表有关联时,删除整个表可能造成数据乱掉,因此可以在表中新增一列自增的临时列,删除数据后再将这一列删除,上代码: - alter table a add newfield int identity(1,1);
- delete a
- where newfield not in
- (select min(newfield) from a group by Prodid,Proddes)
- alter table a drop column newfield
alter table a add newfield int identity(1,1);
delete a
where newfield not in
(select min(newfield) from a group by Prodid,Proddes)
alter table a drop column newfield
版权声明:本文为qq_34386891原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。