The import utility can be used to move data both from and into typed tables while preserving the data's preexisting hierarchy. If desired, import can also be used to create the table hierarchy and the type hierarchy.
The movement of data from one hierarchical structure of typed tables to another is done through a specific traverse order and the creation of an intermediate flat file during an export operation. In turn, the import utility controls the size and the placement of the hierarchy being moved, using the CREATE, INTO table-name, UNDER, and AS ROOT TABLE parameters. As well, import determines what is placed in the target database. For example, it can specify an attributes list at the end of each subtable name to restrict the attributes that are moved to the target database. If no attributes list is used, all of the columns in each subtable are moved.
The type of import you are able to perform depends on the file format of the input file. When working with ASC or DEL data, the target table or hierarchy must exist before the data can be imported. However, data from a PC/IXF file can be imported even if the table or hierarchy does not already exist if you specify an import CREATE operation. It must be noted that if the CREATE option is specified, import cannot alter subtable definitions.
The traverse order contained in the input file enables the hierarchies in the data to be maintained. Therefore, the same traverse order must be used when invoking the export utility and the import utility.
For the PC/IXF file format, one need only specify the target subtable name, and use the default traverse order stored in the file.
Although you determine the starting point and the path down the hierarchy when defining the traverse order, each branch must be traversed to the end before the next branch in the hierarchy can be started. The import utility looks for violations of this condition within the specified traverse order.
DB2 CONNECT TO Target_db
DB2 IMPORT FROM entire_hierarchy.ixf OF IXF CREATE INTO
HIERARCHY STARTING Person AS ROOT TABLE
Each type in the hierarchy is created if it does not exist.
If these types already exist, they must have the same definition in
the target database as in the source database. An SQL error (SQL20013N)
is returned if they are not the same. Since a new hierarchy is being
created, none of the subtables defined in the data file being moved
to the target database (Target_db) can exist. Each of the tables in
the source database hierarchy is created. Data from the source database
is imported into the correct subtables of the target database. DB2 CONNECT TO Target_db
DB2 IMPORT FROM entire_hierarchy.del OF DEL INSERT INTO (Person,
Employee(Salary), Architect) IN HIERARCHY (Person, Employee,
Manager, Architect, Student)
The target tables PERSON, EMPLOYEE, and ARCHITECT must
all exist. Data is imported into the PERSON, EMPLOYEE, and ARCHITECT
subtables. That is, the following will be imported: DB2 CONNECT TO Source_db
DB2 EXPORT TO Student_sub_table.del OF DEL SELECT * FROM
Regular_Student
DB2 CONNECT TO Target_db
DB2 IMPORT FROM Student_sub_table.del OF DEL METHOD P(1,2,3,5,4)
MODIFIED BY NO_TYPE_ID INSERT INTO HIERARCHY (Student)
In this example, the target table STUDENT must exist.
Since STUDENT is a subtable, the modifier no_type_id is
used to indicate that there is no Type_id in the first column. However,
you must ensure that there is an existing Object_id column, in addition
to all of the other attributes that exist in the STUDENT table. Object-id
is expected to be the first column in each row imported into the STUDENT
table. The METHOD clause reverses the order of
the last two attributes.