Example of an Import Task Set Virtual |
A sales representative has been entering details about new clients from Sydney and some reservations they have booked. These new data must now be transferred from a laptop to the application (imported into the application). Suppose the person data is in one external file; persons.TXT, and the corresponding reservations data in another file; reservations.TXT. These two external files must be merged before they are written to the PERSON and RESERVATION tables. The structure of these files is the same as the structure of the PERSON and RESERVATION tables. The files contain primary key values for each person and each reservation. These primary key IDs have been generated on an external system. They must not be imported. Instead, your application must be allowed to generate suitable primary key IDs for these new data. The reservation data includes a foreign key referring to the person primary key in the other file. This foreign key will allow you to join the reservation data with the right person data. Performance can be gained by retrieving the primary key value once for the entire set of children. This value will be stored in a virtual column of the parent external set. To define the two external sets to be used:
To define an import task based on the external sets you just defined: This import task must contain two import SQL Statements. One to insert new data into the PERSON table and another to insert data into the RESERVATION table. This import task must also be associated with both of the external sets you just defined.
The first import SQL statement should insert all data from persons.TXT into the PERSON table except the primary key values, which you want the application to generate for you.
INSERT INTO person ( <all columns EXCEPT the Primary Key-column(s)> ) SELECT <all columns EXCEPT the Primary Key-column(s)> FROM IMP_PERSON How to store the value in a virtual column of the parent external set: If each parent has several children, performance can be gained by retrieving the primary key value in the batch environment once for the entire set of children.
Virtual Name: VIRT1, Data Type NUMBER, Length 4
Sequence: 2 Description: Get generated Person PK into new_res SQL Statement: UPDATE IMP_PERSON np SET virt1 = ( SELECT p.person_id FROM person p WHERE p.first_name = np.first_name AND p.family_name = np.family_name AND p.birth_date = np.birth_date)
Sequence: 3 Description: Import Reservation data except PK; FK from virtual SQL Statement: INSERT INTO reservation ( schedtour_id , made_by , num_part , dealt_with_by , price , book_date , cancel_date ) SELECT nr.schedtour_id , np.virt1 , nr.num_part , nr.dealt_with_by , nr.price , nr.book_date , nr.cancel_date FROM IMP_RESERVATION nr, IMP_PERSON np WHERE np.person_id = nr.made_by |