数据泵对已经存在的表加载索引 imp 和impdp

这里探讨了使用imp 和impdp对含有索引的表的导入的一点差别。

使用imp可以在表存在的情况下,不删除表,且导入表的数据和索引。

1)创建实验表cust(已存在)

SQL> conn scott/yang
已连接。
SQL> select * from cust;

        ID CUTNAME                                                             
---------- ----------                                                          
         1 JANE                                                                
         2 Jone                                                                
         3 TOM                                                                 
         4 yang                                                                 
         5 yangyi                                                              
         6 xiaonan                                                             
已选择6行。
SQL> create index indcust_id on cust(id);
索引已创建。
2)导出表

HOST exp scott/yang file=cust.dmp   tables=cust

连接到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集

即将导出指定的表通过常规路径...
. . 正在导出表                            CUST导出了           6 行
成功终止导出, 没有出现警告。

SQL> drop index indcust_id;
索引已删除

3)使用imp导入表

SQL> HOST imp scott/yang file=cust.dmp    tables=cust  ignore=y

连接到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

经由常规路径由 EXPORT:V11.01.00 创建的导出文件
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 SCOTT 的对象导入到 SCOTT
. 正在将 SCOTT 的对象导入到 SCOTT
. . 正在导入表                          "CUST"导入了           6 行
成功终止导入, 没有出现警告。
SQL> select * from cust;

        ID CUTNAME                                                             
---------- ----------                                                          
         1 JANE                                                                
         2 Jone                                                                
         3 TOM                                                                 
         4 yang                                                                 
         5  yangyi                                                              
         6 xiaonan                                                             
         1 JANE                                                                
         2 Jone                                                                
         3 TOM                                                                 
         4 yang                                                                 
         5 yangyi                                                                                                                      
         6 xiaonan                                                             
已选择12行。
SQL> select index_name from user_indexes
  2  where table_name='CUST';

INDEX_NAME                                                                     
------------------------------                                                 
INDCUST_ID          

4)impdp的默认工作并非如此,监测到表存在时,impdp会跳过索引的创建                                                        

SQL> create table texp(id number,name varchar2(30));

表已创建。

SQL> insert into texp
  2  select rownum,tname
  3  from tab;
已创建9行。
SQL> commit;
提交完成。
SQL> create index indtexp_id on texp (id);
索引已创建。

5)导出表

expdp scott/yang  directory=dump dumpfile=scottexp.dp tables=texp

连接到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=dump dumpfile=scotttexp.dmp tables=texp
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . 导出了 "SCOTT"."TEXP"                              5.507 KB       9 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLE_01 的转储文件集为:
  F:\DUMP\SCOTTTEXP.DMP
作业 "SCOTT"."SYS_EXPORT_TABLE_01" 已于 23:29:38 成功完成


清除数据,并删除索引:
SQL> drop index indtexp_id;
索引已删除。
SQL> truncate table texp;
表被截断。

6)然后再导入表

impdp scott/yang  directory=dump dumpfile=scottexp.dp tables=texp
SQL> select count(*) from texp;

  COUNT(*)                                                                     
----------                                                                     
         9                                                                     
SQL> select index_name from user_indexes
  2  where table_name='TEXP';
未选定行

数据虽然导入了,但是索引没有创建。不过要解决这个问题也很简单,通过INCLUDE就可以解决这个问题:
SQL> truncate table texp;
表被截断。
impdp scott/yang directory=dump  dumpfile=scottexp.dp tables=texp table_exists_action=truncate include=index    

 连接到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表 "SCOTT"."SYS_IMPORT_TABLE_01"
启动 "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=dump dumpfile=scotttexp.dmp tables=texp table_exists_action=truncate include=index
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
作业 "SCOTT"."SYS_IMPORT_TABLE_01" 已于 23:35:39 成功完成

SQL> select count(*) from texp;
  COUNT(*)                                                                     
----------                                                                     
         0                                                                
SQL> select index_name from user_indexes
  2  where table_name='TEXP';
INDEX_NAME                                                                     
------------------------------                                                 
INDTEXP_ID    

 SQL> drop index indtexp_id;
索引已删除。

impdp  scott/yangdirectory=dump dumpfile=scotttexp.dmp tables=texp table_exists_action=truncate include=index include=table_data

连接到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表 "SCOTT"."SYS_IMPORT_TABLE_01"
启动 "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=dump dumpfile=scotttexp.dmp tables=texp table_exists_action=truncate include=index include=table_data
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "SCOTT"."TEXP"                              5.507 KB       9 行
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
作业 "SCOTT"."SYS_IMPORT_TABLE_01" 已于 23:37:57 成功完成

最后检查一下是否成功
SQL> select count(*) from texp;
  COUNT(*)                                                                     
----------                                                                     
         9                                                                     
SQL> select index_name from user_indexes
  2  where table_name='TEXP';
INDEX_NAME                                                                     
------------------------------                                                 
INDTEXP_ID                                                                     

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-664400/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22664653/viewspace-664400/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值