MySQL第十二课 删除完全相同的数据

场景

        现场表结构没有设置主键,导致数据库插入数据存在多个完全相同的记录,需要删除完全相同数据。

方案一:

        1)启动Navicat,过滤掉重复数据,采用distict关键字

        select DISTINCT(id), xm, zjhm, sfzz, dhhm, xgrq,dw, bm, zw,gw from cs_oth_airport_person

        2)点击导出按钮,将数据记录导出成sql文本

        3)清空表之后,重新导入数据库

方案二:

        1)创建新表

            create table cs_oth_airport_person_new like cs_oth_airport_person;

        2)插入去重数据

            insert into cs_oth_airport_person_new select DISTINCT * from cs_oth_airport_person;

        3)删除旧表

            drop table cs_oth_airport_person

        4)  更改名称

             alter table cs_oth_airport_person_new rename to cs_oth_airport_person;


猜你喜欢

转载自blog.51cto.com/fengyuzaitu/2687655