ScriptTransfer Method
Esta característica se quitará en una versión futura de Microsoft SQL Server. Evite utilizar esta característica en nuevos trabajos de desarrollo y tenga previsto modificar las aplicaciones que actualmente la utilizan.
The ScriptTransfer method generates a Transact-SQL command batch that creates database objects contained in the Transfer object indicated.
Sintaxis
object
.ScriptTransfer(
Transfer
, [ ScriptFileMode ] , [ ScriptFile ] )asString
Parts
- object
Expression that evaluates to an object in the Applies To list.
- Transfer
Transfer object that defines the database object and data copy.
- ScriptFileMode
Optional. A long integer that overrides default scripting behavior as described in Settings.
- ScriptFile
Optional. A string that specifies an operating system path or file as an additional target for the generated Transact-SQL script(s) as described in Settings.
Prototype (C/C++)
HRESULT ScriptTransfer(
LPSQLDMOTRANSFER TransferSpec,
SQLDMO_XFRSCRIPTMODE_TYPE ScriptFileMode = SQLDMOXfrFile_Default,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPBSTR ScriptText = NULL);
[!NOTA] SQL Distributed Management Objects (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 using SysFreeString.
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. |
Returns
A Transact-SQL command batch as a string.
Notas
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
Create a Transfer object.
Populate the object using the AddObject or AddObjectByName method.
If desired, set the ScriptType and Script2Type properties to control content of the command batch file(s) generated.
Call the ScriptTransfer method indicating the Transfer object created in Step 1, optionally indicating an output location or a single output file.
[!NOTA] SQL-DMO object scripting methods are fully compatible with an instance of 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 an instance of SQL Server 7.0. Where provided, you can use optional scripting arguments, such as SQLDMOScript2_NoFG to remove some syntax of an instance of SQL Server 7.0.