temp_table: 是一张临时表
a :是要处理的表(有重复数据的)
--把 a的记录distinct后的结果放入到temp_table
select distinct * into temp_table from a
--把a表的记录清空
delete from a
--把temp_table表的数据(没有重复记录),插入到a表
insert into a select * from temp_table
--删除临时temp_table
drop table temp_table
本文介绍了一种通过创建临时表来去除数据库表中重复记录的方法。首先将原始表中的唯一记录复制到临时表中,然后清空原始表,并将临时表中的非重复数据重新插入到原始表中,最后删除临时表。
temp_table: 是一张临时表
a :是要处理的表(有重复数据的)
--把 a的记录distinct后的结果放入到temp_table
select distinct * into temp_table from a
--把a表的记录清空
delete from a
--把temp_table表的数据(没有重复记录),插入到a表
insert into a select * from temp_table
--删除临时temp_table
drop table temp_table

被折叠的 条评论
为什么被折叠?