淘先锋技术网

首页 1 2 3 4 5 6 7
目标删除数据量不是很大的情况下,数据库表多字段的重复的记录:
id为sequence

create table table_tmp 
as (select distinct aa,bb,cc,dd from table);-----创建临时表,并保存不重复的数据

truncate stompcomment cascade----清空原表数据,并清空通过外键约束引用被清空的表的表
或者,delete from stompcomment;-----清空原表数据
两者不同是前者可以立即回收表的存储空间

insert into table select nextval('table_sequence'::regclass) as seq,* from table_tmp----将临时表的数据写回到原表中

drop table table_tmp;--------删除临时表