The ScriptTransfer method generates a Transact-SQL command batch that creates database objects contained in the Transfer object indicated.
object.ScriptTransfer( Transfer , [ ScriptFileMode ] , [ ScriptFile ] )
as String
Part | Description |
---|---|
object | Expression that evaluates to an object in the Applies To list. |
Transfer | Transfer object defining the database object and data copy. |
ScriptFileMode | Optional. A long integer overriding default scripting behavior as described in Settings. |
ScriptFile | Optional. A string specifying an operating system path or file as an additional target for the generated Transact-SQL script(s) as described in Settings. |
Setting the ScriptFileMode argument affects interpretation of the ScriptFile argument. When setting ScriptFileMode, use these values, setting ScriptFile as described.
Constant | Value | Description |
---|---|---|
SQLDMOXfrFile_Default | 1 | SQLDMOXfrFile_ SummaryFiles. |
SQLDMOXfrFile_SingleFile | 2 | Command batch is written to one file. Specify the file name using the ScriptFile argument. If a path is not included in the file name, the file is created in the directory indicated by the client computer environment variable TEMP. |
SQLDMOXfrFile_SingleFilePerObject | 4 | Command batch is written to multiple files, one file for each SQL Server component transferred. Specify a path using the ScriptFile argument. If a path is not specified, the files are created in the directory indicated by the client computer environment variable TEMP. |
SQLDMOXfrFile_SingleSummaryFile | 8 | Command batch is written to one file. Command batch contents are organized by object type. Specify the file name using the ScriptFile argument. If a path is not included in the file name, the file is created in the directory indicated by the client computer environment variable TEMP. |
SQLDMOXfrFile_SummaryFiles | 1 | Command batch is written to multiple files, one file for each kind of object transferred. For example, generate a file for user-defined data types and a separate file for tables. Specify a path using the ScriptFile argument. If a path is not specified, the files are created in the directory indicated by the client computer environment variable TEMP. |
A Transact-SQL command batch as a string.
Use the ScriptTransfer method to capture the database object creation statements (schema transfer) specified by a Transfer object. The command batch file(s) created can be used in another process, such as a scheduled transfer of database schema.
To use the ScriptTransfer method
Note SQL-DMO object scripting methods are fully compatible with SQL Server version 7.0. However, database compatibility level affects Transact-SQL command batch contents.
When scripting a database with a compatibility level of less than 7.0, or when scripting any of its objects, the resulting Transact-SQL command batch includes only keywords reserved by that level.
Transact-SQL command syntax is always compliant with SQL Server 7.0. Where they are provided, you can use optional scripting arguments, such as SQLDMOScript2_NoFG to remove some version 7.0 specific syntax.
HRESULT ScriptTransfer(
LPSQLDMOTRANSFER TransferSpec,
SQLDMO_XFRSCRIPTMODE_TYPE ScriptFileMode = SQLDMOXfrFile_Default,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPBSTR ScriptText = NULL);
Note SQL-DMO strings are always returned as OLE BSTR objects. A C/C++ application obtains a reference to the string. The application must release the reference by using SysFreeString.