0% found this document useful (0 votes)
34 views26 pages

05 - Data Movement

The document discusses loading large amounts of data into a database. It explains that the INSERT statement has limitations for large loads due to overhead. The IMPORT command is slower for large loads than LOAD but allows creation of tables and indexes. LOAD is faster but requires tables and indexes to already exist. Exception tables should be created to store rows that violate constraints. After LOAD, the SET INTEGRITY command may be needed to resolve the Set Integrity Pending table state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views26 pages

05 - Data Movement

The document discusses loading large amounts of data into a database. It explains that the INSERT statement has limitations for large loads due to overhead. The IMPORT command is slower for large loads than LOAD but allows creation of tables and indexes. LOAD is faster but requires tables and indexes to already exist. Exception tables should be created to store rows that violate constraints. After LOAD, the SET INTEGRITY command may be needed to resolve the Set Integrity Pending table state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

ADMINISTRASI BASIS DATA

Data Movement
Unit objectives

• After completing this unit, you should be able to:


• Discuss the INSERT statement and recognize its limitations
• Explain the differences between IMPORT and LOAD
• Explain the EXPORT, IMPORT, and LOAD syntax
• Create and use Exception Tables and Dump-Files
• Distinguish and resolve Table States:
• Load Pending and Set Integrity Pending
• Use the SET INTEGRITY command
Review INSERT statement

• The SQL INSERT statement can insert one or more rows of data into tables, nicknames, or views:
• SQL overhead is imposed, such as obeying RI, or Check Constraints, or Uniqueness, or executing triggers.
• As INSERTs occur, the activity is also stored in logs
• The SQL INSERT might not be the best or fastest method to load massive amounts of data into a
database
• Example inserts:
• insert into artists (artno, name, classification) values (100, 'Patti & Cart Wheels', 'S');
• Insert into emptemp select * from employee ;
EXPORT/IMPORT overview

• Must be connected prior to call


EXPORT command syntax (Basic)
EXPORT command example

• Exports data from database tables to file


• Check message for error or warning messages

• db2 connect to musicdb


• db2 export to artexprt of ixf messages artmsg select
artno, name from artists
IMPORT command syntax (Basic)
IMPORT command example

• Imports data from a file to a database table

• Imports data from a file to three DMS table spaces


Differences between IMPORT and LOAD

IMPORT LOAD
Slow when moving large amounts Faster for large amounts of data
of data
Creation of table/index supported Tables and indexes must exist
with IXF format
Import into tables, views, aliases Load into tables only
Option to ALLOW WRITE ACCESS Existing data can still be seen by
read applications
All rows logged Minimal logging; can make copy
Triggers fired, constraints Triggers not fired; unique
enforced constraints enforced, RI and
check constraints via SET
INTEGRITY
Four phases of Load
LOAD: Load phase

• During the LOAD phase, data is stored in a table and index keys are
collected
• Save points are established at intervals
• Messages indicate the number of input rows successfullyloaded
• If a failure occurs in this phase, use the RESTART option for LOAD to
restart from the last successful consistency point
LOAD: Build phase

• During the BUILD phase, indexes are created based on the


index keys collected in the Load phase
• The index keys are sorted during the Load phase
• If a failure occurs during this phase, LOAD restarts from
the BUILD phase
LOAD: Delete phase

• During the DELETE phase, all rows that have violated a unique
constraint are deleted
• If a failure occurs, LOAD restarts from the DELETE phase
• Once the database indexes are rebuilt, information about the rows
containing the invalid keys is contained in an exception table,WHICH
SHOULD BE CREATED BEFORE LOAD
• Finally, any duplicate keys found are deleted
LOAD: Index Copy phase

• The index data is copied from a system temporary table


space to the original table space.
• This will only occur if a system temporary table space was
specified for index creation during a load operation with
the READ ACCESS option specified.
LOAD command syntax (Basic)
LOAD scenario
Rules and methods for creating Exception
Tables

• The first ncolumns are the same


• No constraints and no trigger definitions
• n+ 1 column TIMESTAMP
• n+ 2 column CLOB (32 KB)
• user INSERT privilege
Offline versus Online Load

• ALLOW NO ACCESS

• ALLOW READ ACCESS


Table states

• (Load pending, Set Integrity Pending)


• LOAD QUERY TABLE <table-name>
• Tablestate:
• Normal
• Set Integrity Pending
• Load in Progress
• Load Pending
• Reorg Pending
• Read Access Only
• Unavailable
• Not Load Restar
• tableUnknown
• Table can be in several states at same timeTablestate:Set Integrity PendingLoad in ProgressRead
Access Only
Load Pending state:
Recovering from LOAD failure

• Restart the Load:


• Check Messages files
• Use Restart option
• Load operation automatically continues from last consistency point in Load or Build phase
• or Delete phase if ALLOW NO ACCESS

• Replace the whole table


• LOAD ... REPLACE
• Terminate the Load:
• If LOAD ... INSERT, returns table to state preceding Load
• If LOAD ... REPLACE, table will be truncated to an empty state
• Create backup copy prior to Load to return to state preceding Load

Do not tamper with Load temporary files


Backup Pending state: COPY options

• When loading data and forward recovery is enabled:


• COPY NO (default)
• During load, Backup pendingandLoad in progress
• After load, Backup Pending
• COPY YES
• Load has made Copy not Backup pending
• NONRECOVERABLE
• No copy made and no backup required
Set Integrity Pending table state

• Load turns OFF constraint checking:


• Leaves table in Set Integrity Pending state
• If parent table is in Set Integrity Pending, then dependents mayalso be in Set
Integrity Pending
• LOAD INSERT, ALLOW READ ACCESS
• Loaded table in Set Integrity Pending with read access
• LOAD INSERT, ALLOW NO ACCESS
• Loaded table in Set Integrity Pending with no access
• LOAD REPLACE, SET INTEGRITY PENDING CASCADE DEFERRED
• Loaded table in Set Integrity Pending with no access
• LOAD REPLACE, SET INTEGRITY PENDING CASCADE IMMEDIATE
• Loaded table and descendant foreign key tables are in Set Integrity Pending with no
access
SET INTEGRITY command syntax (Basic)
Set Integrity Pending state
Meaningful steps for LOAD

• Create tables and indexes


• Create exception tables
• Sort data
• Back up TS/DB (if using REPLACE)
• Consider freespace
• Load .... for Exception ... Savecount ... Warningcount...
• Examine xx.msg and dumpfile (after LOAD completes)
• Examine exception tables (after LOAD completes)
• Back up table space if log retain=recovery and COPY NO
• Set Integrity for .... (only if table in Set Integrity Pending state)
• Update statistics (if necessary)
Unit summary

Having completed this unit, you should be able to:


• Discuss the INSERT statement and recognize its limitations
• Explain the differences between IMPORT and LOAD
• Explain the EXPORT, IMPORT, and LOAD syntax
• Create and use Exception Tables and Dump-Files
• Distinguish and resolve Table States:
• Load Pending and Set Integrity Pending •
• Use the SET INTEGRITY command

You might also like