1.查询不重复的数据存到临时表里,删除掉原表,然后将临时表的数据存到原表里,上代码:
[sql]
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.当原表和其他表有关联时,删除整个表可能造成数据乱掉,因此可以在表中新增一列自增的临时列,删除数据后再将这一列删除,上代码:
[sql]
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