Você está na página 1de 1

Chapter 2: Inserting 63

LOAD TABLE statement might sit and wait before starting to run because it
cant get the exclusive lock, and once it starts running other users might be
blocked until LOAD TABLE finishes. LOAD TABLE doesnt do commits
along the way, just one commit if it works or a rollback if it fails.
The third shortcut is that LOAD TABLE does not write the individual
inserted rows to the transaction log file, just a record of the LOAD TABLE
command itself. This means that LOAD TABLE should not be used on a table
that is being uploaded via MobiLink if you want the inserted rows to be
included in the upload stream. MobiLink determines which rows to upload by
examining the transaction log, and rows inserted via LOAD TABLE will be
missed. (For more information about MobiLink, see Chapter 7,
Synchronizing.)
The third shortcut also has implications for recovery using the transaction
log if WITH CHECKPOINT isnt specified to force a checkpoint when the
LOAD TABLE is finished. Since the transaction log only contains the LOAD
TABLE command itself, not the individual rows, the original file must still be
available for a recovery process to work.
Here is an example to show what LOAD TABLE actually writes to the
transaction log:
CREATE TABLE t1 (
key_1 INTEGER NOT NULL,
col_2 INTEGER NOT NULL,
PRIMARY KEY ( key_1 ) );

LOAD TABLE t1 FROM 't1_d.txt';


The dbtran.exe utility can be used to reformat the operations recorded in the
transaction log file into SQL statements in a text file. The following example
shows what it produces for the LOAD TABLE above. Note that there is no
information about the individual rows, just the original LOAD TABLE state-
ment itself plus a CHECKPOINT.
--CHECKPOINT-0000-0000507397-2003/oct/27 14:57
...
--SQL-1001-0000466662
load into table t1 from 't1_d.txt'
go

Note: LOAD TABLE automatically performs a checkpoint before the load


operation is started, as shown in the dbtran output above. This is different from
the optional checkpoint that is performed after the LOAD TABLE is completed if
you specify the WITH CHECKPOINT option.

LOAD TABLE has another advantage besides speed: It is a mechanism


whereby a statement inside a stored procedure can load data from a text file into
a table; no client application or interface is required.
If you are willing to give up some speed to avoid the disadvantages of all
three shortcuts described above, while still taking advantage of the fact that
LOAD TABLE can be used from inside a stored procedure, you can use a tem-
porary table in the LOAD TABLE and then copy the data via INSERT. Here is
how the LOAD TABLE from the previous example can be changed to use a
temporary table:

Você também pode gostar