Question

I am trying to do an import using data pump, but I am struggling to come up with the right options. The export was taken as a schema export. I am trying to import just the tables, with no other database objects.

I am currently using

INCLUDE=TABLE
TABLE_EXISTS_ACTION=REPLACE
REMAP_SCHEMA=
REMAP_TABLESPACE=

This is correctly importing the tables, but I am a little surprised to see that the import is also creating the constraints and triggers on the tables, or trying to at least. The triggers are failing because they include a schema name that does not exist in the database.

I thought that by using INCLUDE=TABLE only the tables would be included. Apparently that is not the case. I am unable to use EXCLUDE=CONSTRAINT or EXCLUDE=TRIGGER as I am already using INCLUDE to limit the import to just tables.

Any ideas on how I could structure the import to only import tables?

Was it helpful?

Solution

You are right when stating I thought that by using INCLUDE=TABLE only the tables would be included, but it includes all related objects too. This means that constraints and triggers will be created for you when you use INCLUDE=TABLE when importing.


Possible Solution

If you have the possibility to re-create the dump using the expdp command then you might want to just export the tables of the required schema and use the INCLUDE parameter.

INCLUDE

Purpose: Enables you to filter the metadata that is exported by specifying objects and object types for the current export mode. The specified objects and all their dependent objects are exported. Grants on these objects are also exported.

exp_include.par

This is basically the expdp parameter file.

FULL=N
...
SCHEMAS=<your_schema(s)>
INCLUDE=TABLE
...

This will create a dump of the required schema and contain only tables and dependant objects.


After you have generated the required *.dmp file, import using the EXCLUDE=... option.

EXCLUDE

Purpose: Enables you to filter the metadata that is imported by specifying objects and object types to exclude from the import job.

imp_exclude.par

This is the parameter file for the impdp.

FULL=Y
...
EXCLUDE=STATISTIC
EXCLUDE=CONSTRAINT
EXCLUDE=TRIGGER
...

This should result in the tables being imported correctly.

Reference Material

OTHER TIPS

The parameters EXCLUDE and INCLUDE cannot be specified in the same import job. You can use one of the following methods achieve that tables and indexes, but no triggers, constraints or referential constraints are imported. If you don't want indexes, too, you can exclude them from import in a similar way.

Method 1: You include tables in your import and use further INCLUDE directives to exclude triggers, constraints and referential constraints from import. One specifies the following:

INCLUDE=TABLE
INCLUDE=TRIGGER:"=''"
INCLUDE=CONSTRAINT:"=''"
INCLUDE=REF_CONSTRAINT:"=''"

There is not trigger that satisfies the given clause which means, that the trigger name is an empty string. The same holds for the constraint and referentali constraints

Methode 2: You do not use the INCLUDE directive to specify that only tables should be imported but use a different method. Than you can use EXCLUDE to avoid the import of triggers, constraints and referential constraints.

You can specify the list of tables you wand to import in a table import

TABLES=owner1.table1, owner2.table2, ...
EXCLUDE=TRIGGER, CONSTRAINT, REF_CONSTRAINT

If the list of tables is large than this method is not very useful.

Another way to specify tables only is to use a tablespace import. The number of tablespaces used by the tables in the dump file is usually much smaller than the numbers of tables

TABLESPACES=tablespace1,  tablespace2, ...
EXCLUDE=TRIGGER, CONSTRAINT, REF_CONSTRAINT

Examples

I use Oracle Database 11.2.0.4 Enterprise Edition for these examples.

I created a schema SCOTT with some tables, triggers, procedures, constraints and referential constraints. Then I did a schema export with the following parameters

directory=SCOTT
schemas=SCOTT
dumpfile=schema.dmp
logfile=exp_schema.log

Here are the relevant parts of the logfile of this export

Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** parfile=exp_schema.par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
. . exported "SCOTT"."DEPT"                              5.929 KB       4 rows
. . exported "SCOTT"."EMP"                               8.562 KB      14 rows
. . exported "SCOTT"."SALGRADE"                          5.859 KB       5 rows
. . exported "SCOTT"."BONUS"                                 0 KB       0 rows
. . exported "SCOTT"."JOB_HISTORY"                           0 KB       0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

So user, grants, procedures, constaints, referential constraints, trigger and the five tables DEPT,EMP,SALGRADE; BONUS, JOB_HISTORY of user SCOTT are exported.

Now I will not import this dump in a database but I will only create an SQL-file with the statements that will be executed by the import. This can be achieved by the parameter SQLFILE in the import paramter file.

First I do a full import of the dumpfile. This will import everything form the dump file

directory=SCOTT
full=y
dumpfile=schema.dmp
logfile=imp_full.log
sqlfile=full.sql

This result in the following

Master table "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_SQL_FILE_FULL_01":  system/******** parfile=imp_full.par
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Job "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully completed 

If one does a schema output using

directory=SCOTT
schemas=SCOTT
dumpfile=schema.dmp
logfile=imp_schema.log
sqlfile=schema.sql

a similar logfile is created.

Now we include only the tables

directory=SCOTT
full=y
dumpfile=schema.dmp
logfile=imp_schema_inc.log
sqlfile=schema_inc.sql
include=table

This results in the following log file:

Starting "SYSTEM"."SYS_SQL_FILE_FULL_01":  system/******** parfile=imp_schema_inc.par
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Job "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully completed 

The tables an the dependent objects are created. Now we use further INCLUDE directives to avoid the import of the unwanted objects:

directory=SCOTT
full=y
dumpfile=schema.dmp
logfile=imp_schema_inc_inc.log
sqlfile=schema_inc_inc.sql
include= table
include=trigger:"=''"
include=constraint:"=''"
include=ref_constraint:"=''"

This results in exactly what we want:

Starting "SYSTEM"."SYS_SQL_FILE_FULL_01":  system/******** parfile=imp_schema_inc_inc.par
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Job "SYSTEM"."SYS_SQL_FILE_FULL_01" successfully completed

If we use a table import and specify these 5 tables and exclude the unwanted objects , we get a similar log file

directory=SCOTT
tables=SCOTT.DEPT,SCOTT.EMP,SCOTT.SALGRADE,SCOTT.BONUS,SCOTT.JOB_HISTORY
dumpfile=schema.dmp
logfile=imp_tables.log
sqlfile=tables.sql
exclude=trigger, constraint,ref_constraint

We also get such a logfile if we use a tablespace import. All objects of user SCOTT are in the tablespace USERS.

directory=SCOTT
dumpfile=schema.dmp
logfile=imp_tablespaces.log
sqlfile=tablespaces.sql
tablespaces=users
exclude=trigger, constraint, ref_constraint
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top