数据库id重复删除操作:
①新增字段uid
ALTER TABLE BASECOVER.BASE_UNIT ADD UID VARCHAR(100) NULL;
②uid生成随机唯一编码:
达梦数据库:
UPDATE basecover.BASE_UNIT
SET uid=sys_GUID()
MySQL数据库:
UPDATE basecover.BASE_UNIT
SET uid=replace(uuid(),"-","")
oracle数据库:
UPDATE basecover.BASE_UNIT
SET uid=rawtohex(sys_guid())
③分组删除最小uid
delete from BASECOVER.BASE_UNIT
where uid not in(
select min_id from (
select
min(uid) as min_id
from BASECOVER.BASE_UNIT
group by id
) as x
);
④删除uid字段
ALTER TABLE BASECOVER.BASE_UNIT DROP COLUMN UID;
⑤设置id为唯一
ALTER TABLE BASECOVER.BASE_UNIT ADD CONSTRAINT BASE_UNIT_PK PRIMARY KEY (ID);