ScriptTransfer Method

Description

Creates Transact-SQL script file(s) used by the Transfer method for creating copied objects in the destination database. Set the properties of a created Transfer object as desired, pass that Transfer object to the ScriptTransfer method with tScriptMode set to SQLOLEXfrFile_SummaryFiles to create the script files, and then pass the same Transfer object to the Transfer method to perform the database transfer.

Visual Basic

strScript = Database.ScriptTransfer (
[TransferSpec :=] Transfer,
[[ScriptFileMode :=] tScriptMode,]
[[ScriptFilePath :=] strFile] )

C++

HRESULT pDatabase->ScriptTransfer (
LPSQLOLETRANSFER
pTransfer,
SQLOLE_XFRSCRIPTMODE_TYPE tScriptMode = SQLOLEXfrFile_Default,
SQLOLE_LPCSTR strFile = NULL,
SQLOLE_LPBSTR pstrScript = NULL );

Elements


Element Type Description

strScript String Returned Transact-SQL script
Transfer Transfer Created Transfer object that specifies how to execute the database transfer
tScriptMode SQLOLE_XFRSCRIPTMODE
_TYPE
The script transfer type
strFile String If tScriptMode is SQLOLEXfrFile_SingleFile, the full path and filename of the single script file; otherwise, the full path of the directory used to store the script files

Remarks

When tScriptMode is SQLOLEXfrFile_SummaryFiles (the default), multiple script files are created that have names of the following form:

source_server.source_database.ext

where source_server is the name of the SQL Server that contains the source database, source_database is the name of the source database, and ext is one of the following three-letter extensions that are used to create database objects...


File
extension
Script
creates

LGN Logins
GRP Groups, group statement privileges
USR Users, user statement privileges
DEF Non-declarative referential integrity (DRI) defaults
RUL Rules
UDT User-defined datatypes
TAB Tables (does not include DRI)
DR1 Table DRI before copying data (includes clustered primary and unique keys)
DR2 Table DRI after copying data (includes nonclustered primary and unique keys, CHECK constraints, and DRI defaults)
ID1 Table indexes created before copying data (includes clustered
non-DRI indexes)
ID2 Table indexes created after copying data (includes nonclustered
non-DRI indexes)
BND Bindings for rules and non-DRI defaults
PRV Table privileges
FKY Foreign keys
TRG Triggers
VIW Views and view privileges
PRC Stored procedures and stored procedure privileges

...or one of the following three-letter extensions that are used to drop database objects.


Extension Script drops

DP1 Drops foreign keys that reference copied tables (listed in the file with the DP2 extension). The Transfer method does not run this script. After a transfer is complete, you can run the DP1 script followed by the DP2 script on the source database to drop the source objects.
DP2 Drops all objects to be copied. (DP2 is used on the destination database only when the Transfer.DropDestObjectsFirst property is set to True).

The Database.Transfer method runs these script files in the following order: DP2, LGN, GRP, USR, DEF, RUL, UDT, TAB, DR1, ID1, bulk copy of copied tables, DR2, ID2, BND, PRV, FKY, TRG, VIW, PRC.

To create the transfer scripts for private use (and not for later use with the Transfer method) you can set tScriptMode to SQLOLEXfrFile_SingleFilePerObject or SQLOLEXfrFile_SingleFile.

When tScriptMode is SQLOLEXfrFile_SingleFilePerObject, multiple files are created that have names of the following form:

owner.object.ext

where owner is the username of the object owner, object is the name of the database object, and ext is one of the extensions listed above.

When tScriptMode is SQLOLEXfrFile_SingleFile, a single file (specified in strFile) is created that contains the entire Transact-SQL script for creating the database objects in the destination database.