Loads a backup copy of one of the following:
For additional syntax information for the LOAD statement, see the Microsoft SQL Server Transact-SQL Reference.
The LOAD TRANSACTION statement supports the STOPAT option, which stops a roll forward at a specified time.
The LOAD TABLE statement loads a backup copy of a table into a database.
The LOAD HEADERONLY statement returns additional columns.
To load a table:
LOAD TABLE [[database.]owner.]table_name
FROM dump_device [, dump_device2 [..., dump_device32]]
[WITH options]
To load a transaction log:
LOAD TRANSACTION {dbname | @dbname_var}
FROM dump_device [, dumpdevice2 [..., dumpdevice32]]
[WITH options]
To load header information:
LOAD HEADERONLY
FROM dump_device
where
Important When specifying a striped dump, you can use both logical device names (or variables) and temporary device names (or variables). PIPE devices have been added to allow third-party vendors a flexible and powerful way to connect their own software. For typical Transact-SQL use, the PIPE device is not used.
The LOAD TABLE statement loads only one table at a time, which provides more control when recovering a database. Loading a table from a database dump is discouraged because if data manipulation transactions were occurring on the table when the database dump was performed, the data in the table may be logically inconsistent. You should load a table from a database dump only in disaster recovery situations, and even then it is important that you understand that the data loaded from the dump may be inconsistent.
When loading a table, use a target table and data source table. The data source table holds the data to be loaded to the target table; it can be a full database backup or an individual table backup.
For example, a company maintains a mailing list that is updated quarterly by an outside agency. The mailing list table has no index. The company wants to replace the existing mailing list with the new, agency-supplied mailing list. You could use a procedure that deletes all of the rows of the old table and inserts new rows, but a more efficient approach is to load the new table from a backup.
When loading a table, an EXCLUSIVE TABLE lock is placed on the table. No one else can read or modify the table while it is being loaded.
Important It is recommended that you load a table only from a table dump file because a table dump file is generated from a locked table. It provides an up-to-date snapshot of the table. If you load a table from a database dump file, you will not get any outstanding transactions because the LOAD TABLE statement does not load transactions from the transaction log.
The schema for the data source table and the target table must match for the load to be successful. The names of the tables can be different if the SOURCE option is specified, but the underlying table structure must be the same in terms of base system types, lengths, and nullability.
Note Once you have performed a load table operation, you must do a full database dump. Until you dump the full database, the transaction log cannot be dumped.
Using LOAD TABLE on a populated table is permitted if you use the APPEND option.
During load operations, triggers, rules, defaults, and declarative referential integrity (FOREIGN KEY, CHECK, PRIMARY KEY) are not enforced.
Important Table loads are not permitted on tables that have text columns, indexes, or are published for replication. Table loads from mixed platforms are not supported. For example, you cannot dump a table on an Alpha-based server and load it into a table on an Intel-based server.
When a transaction log is not completely correct (because of possible user error) and you want to apply transactions up to a certain point in time, use the LOAD TRANSACTION statement with the STOPAT clause. If you are unsure which transaction log contains the stopping time, specify the STOPAT clause for all transaction logs that are being loaded.
For example, suppose a user mistakenly deletes the rows in a table on Sunday, Aug. 4, 1996 at 1:00 p.m. The transaction log's last transaction time was Sunday, Aug. 4, 1996 at 1:30 p.m. The STOPAT option is used to stop the roll forward at 12:55 p.m. on Sunday, Aug. 4, 1996. Transactions are applied up to just prior to the deletion.
The LOAD HEADERONLY statement retrieves all the volume and dump header information for all dumps on a particular dump device. The information is returned in a tabular format. These columns have been added to the LOAD HEADERONLY results set.
New columns | Datatype | Comment |
---|---|---|
BackupStart | datetime | Date and time of the oldest committed transaction. Cannot be NULL. |
BackupFinish | datetime | Date and time of the most recently committed transaction. Cannot be NULL. |
ServerSort | int | Server sort order. Cannot be NULL. This column is valid for database dumps only. |
ServerCodePage | int | Server code page, which is the character set used by the server. Value is 0 when viewing a version 6.0 or earlier dump. |
TableOwner | char(30) | Table owner. |
OperatorName | char(30) | Name of the user performing the dump operation. Cannot be NULL unless viewing a version 6.0 or earlier database backup. |
ProcessorType | int | CPU architecture number. Cannot be NULL. |
SQLVersionMajor | int | Major version number of server that made the dump. Cannot be NULL. Value is 0 when viewing a version 6.0 or earlier dump. |
SQLVersionMinor | int | Minor version number of server that made the dump. Cannot be NULL. Value is 0 when viewing a version 6.0 or earlier dump. |
SQLVersionBuild | int | Build number of server that made the dump. Cannot be NULL. Value is 0 when viewing a version 6.0 or earlier dump. |
This example loads the employee_table from the disk file dump1 into the personnel table.
LOAD TABLE personnel FROM dump1 WITH source='employee_table', APPEND
This example loads a transaction log for the corporate database and stops it on Nov. 4, 1996 at 2:00 p.m..
LOAD TRANSACTION corporate FROM TAPEDUMP1 WITH STOPAT='1996 110414:00:00'
This example loads the header only from a predefined device.
LOAD HEADERONLY FROM dump_dev1
INSERT permission is required to load a table. The target table's database must have the select into/bulkcopy database option set before loading a table.