当前位置:首页 > 开发 > 数据库 > 正文

三张表存在外键引用时清除重复数据

发表于: 2013-08-04   作者:annan211   来源:转载   浏览:
摘要: 干掉 USERCOMPANYINFO 重复信息   1 create table USERCOMPANYINFO_tmp as ( select * from USERCOMPANYINFO where rowid not in (SELECT A.ROWID FROM USERCOMPANYINFO A,(SELECT MAX(A.ROWID) RROWID,COMPAN
干掉 USERCOMPANYINFO 重复信息
 
1 create table USERCOMPANYINFO_tmp as (   
 select * from USERCOMPANYINFO where rowid not in (SELECT A.ROWID FROM USERCOMPANYINFO A,(SELECT MAX(A.ROWID) RROWID,COMPANY FROM USERCOMPANYINFO A GROUP BY A.COMPANY HAVING COUNT(*) > 3) B    
     WHERE A.COMPANY = B.COMPANY AND A.ROWID <> B.RROWID))  
 
  2  alter table USERCOMPANYINFO disable primary key cascade; //清除外部引用  
   3 truncate table USERCOMPANYINFO;//清空数据  
   4 insert into USERCOMPANYINFO select * from USERCOMPANYINFO_tmp; //蒋临时表中的数据倒入目标数据
  5 alter table USERCOMPANYINFO enable primary key; //给目标数据表添加主键约束  

干掉uuser 重复信息

1 create table UUSER_temp as(
select * from UUSER t where t.userid  in(select u.userid from USERCOMPANYINFO u ))  --讲uuser表中的需要的数据 保存到临时表中

 2  drop uuser;//删除表
 3 create table UUSER as select * from UUSER_temp
 4 drop UUSER_temp;


  同理干掉 USERINFO


1 create table USERINFO_temp as(
select * from USERINFO t where t.userinfoid  in(select u.userinfoid from USERCOMPANYINFO u ))  --讲uuser表中的需要的数据 保存到临时表中

 2  drop USERINFO;//删除表
 3 create table USERINFO as select * from USERINFO_temp
 4 drop USERINFO_temp

三张表存在外键引用时清除重复数据

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号