当做 exp导入的时候可能会遇到约束的问题而不能进行导入。
可以使用下面的办法来禁止约束从而使导入顺利完成!
在导入的时候遇到如下问题:
Column 30 MOS
IMP-00019: row rejected due to ORACLE error 2291
IMP-00003: ORACLE error 2291 encountered
ORA-02291: integrity constraint (CMDB.CI_ELEMENT_LOCATION) violated - parent key not found
处理步骤如下:
SQL> create table cmdb.configuration_item_bak as select * from cmdb.configuration_item;
Table created.
SQL> alter table cmdb.configuration_item disable primary key;
alter table cmdb.configuration_item disable primary key
*
ERROR at line 1:
ORA-02297: cannot disable constraint (CMDB.PK_CONFIGURATION_ITEM) -
dependencies exist
SQL> alter table cmdb.configuration_item disable constraint PK_CONFIGURATION_ITEM;
alter table cmdb.configuration_item disable constraint PK_CONFIGURATION_ITEM
*
ERROR at line 1:
ORA-02297: cannot disable constraint (CMDB.PK_CONFIGURATION_ITEM) -
dependencies exist
SQL> alter table cmdb.configuration_item disable constraint PK_CONFIGURATION_ITEM cascade;
Table altered.
SQL> alter table cmdb.configuration_item disable primary key;
Table altered.
SQL> alter table cmdb.configuration_item disable constraint PK_CONFIGURATION_ITEM ;
Table altered.
原以为这样做导入就应该没有问题了:)
imp / file=cmdb.dmp fromuser=cmdb touser=cmdb ignore=y
可问题依旧?
为什么呢。原来这里的约束错误是因为违反了文件里要导入数据的约束条件,这与是否禁止表上面的约束无关。
只是因为表中已经有了和文件里一样的数据导致在导入的时候违反了文件里的约束。
所以可以通过清除表里数据的办法来完成导入。
truncate table cmdb.configuration_item ;
然后导入:
-bash-3.00$ imp / file=cmdb.dmp fromuser=cmdb touser=cmdb ignore=y
Import: Release 11.2.0.2.0 - Production on Wed Aug 17 03:27:17 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning option
Export file created by EXPORT:V11.02.00 via conventional path
import done in UTF8 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
export client uses US7ASCII character set (possible charset conversion)
. importing CMDB's objects into CMDB
. . importing table "CONFIGURATION_ITEM" 21171 rows imported