EXPDP/IMPDP单表住外键

简介: 以前都知道在导入单表的时候主外键会有问题,如果主表不存在你自己直接导入子表会出现问题,今天测试了一下 SQL> create table test  2  as  3  select * from dba_users; Table created alter...

以前都知道在导入单表的时候主外键会有问题,如果主表不存在你自己直接导入子表会出现问题,今天测试了一下

SQL> create table test
  2  as
  3  select * from dba_users;
 
Table created

alter table TEST
add constraint PK_TEST primary key (USER_ID)

SQL> create index ind_test
  2  on test(username);
 
Index created
 
SQL> create table test0
  2  as
  3  select * from v$session;
 

alter table TEST0
add constraint FK_TEST foreign key (USER#)
references TEST (USER_ID);

进行导出

[oracle@b000-vmpomstestdb ~]$ expdp pp/gelc123 tables=test  dumpfile=TEMP_DIR:test20100826.dmp logfile=TEMP_DIR:test20100826.log

Export: Release 10.2.0.1.0 - 64bit Production on Friday, 07 December, 2012 19:25:15

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "PP"."SYS_EXPORT_TABLE_01":  pp/******** tables=test dumpfile=TEMP_DIR:test20100826.dmp logfile=TEMP_DIR:test20100826.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "PP"."TEST"                                 17.93 KB     101 rows
Master table "PP"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for PP.SYS_EXPORT_TABLE_01 is:
  /devrman/expdp/test20100826.dmp
Job "PP"."SYS_EXPORT_TABLE_01" successfully completed at 19:25:25

[oracle@b000-vmpomstestdb ~]$ expdp pp/gelc123 tables=test0 dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log

Export: Release 10.2.0.1.0 - 64bit Production on Friday, 07 December, 2012 19:42:48

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "PP"."SYS_EXPORT_TABLE_01":  pp/******** tables=test0 dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "PP"."TEST0"                                43.98 KB      41 rows
Master table "PP"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for PP.SYS_EXPORT_TABLE_01 is:
  /devrman/expdp/test120100826.dmp

然后进行导入

1、在未导入主表的情况下

[oracle@b000-vmpomstestdb expdp]$ impdp pptest/gelc123  dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log remap_schema=pp:pptest;

Import: Release 10.2.0.1.0 - 64bit Production on Friday, 07 December, 2012 19:43:06

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "PPTEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "PPTEST"."SYS_IMPORT_FULL_01":  pptest/******** dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log remap_schema=pp:pptest
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "PPTEST"."TEST0"                            43.98 KB      41 rows
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
ORA-39083: Object type REF_CONSTRAINT failed to create with error:
ORA-00942: table or view does not exist
Failing sql is:
ALTER TABLE "PPTEST"."TEST0" ADD CONSTRAINT "FK_TEST" FOREIGN KEY ("USER#") REFERENCES "PPTEST"."TEST" ("USER_ID") ENABLE
 
Job "PPTEST"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 19:43:09

2、在导入主表的情况下

[oracle@b000-vmpomstestdb expdp]$ impdp pptest/gelc123  dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log remap_schema=pp:pptest;

Import: Release 10.2.0.1.0 - 64bit Production on Friday, 07 December, 2012 19:57:15

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "PPTEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "PPTEST"."SYS_IMPORT_FULL_01":  pptest/******** dumpfile=TEMP_DIR:test120100826.dmp logfile=TEMP_DIR:test120100826.log remap_schema=pp:pptest
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "PPTEST"."TEST0"                            43.98 KB      41 rows
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "PPTEST"."SYS_IMPORT_FULL_01" successfully completed at 19:57:19

相关文章
|
Oracle 关系型数据库 OLAP
|
Oracle 关系型数据库 数据库
IMPDP
在10g之前,传统的导出和导入分别使用EXP工具和IMP工具,从10g开始,不仅保留了原有的EXP和IMP工具,还提供了数据泵导出导入工具EXPDP和IMPDP.使用EXPDP和IMPDP时应该注意的事项: 1、EXP和IMP是客户端工具程序,它们既可以在可以客户端使用,也可以在服务端使用。
1754 0
|
关系型数据库 数据库 数据安全/隐私保护
EXPDP
OracleDatabase 10g引入了最新的数据泵(DataDump)技术,数据泵导出导入(EXPDP和IMPDP)的作用 1、实现逻辑备份和逻辑恢复. 2、在数据库用户之间移动对象. 3、在数据库之间移动对象 4、实现表空间搬移.
1412 0
|
Oracle 关系型数据库 OLAP
|
数据库 关系型数据库 Oracle
|
存储 SQL 数据库
|
Oracle 关系型数据库 数据库