Script Method (BackupDevice Object)
未來的 Microsoft SQL Server 版本將移除這項功能。請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。
The Script method generates a Transact-SQL command batch that can be used to re-create the Microsoft SQL Server component referenced by the SQL Distributed Management Objects (SQL-DMO) object.
語法
object.Script( [ ScriptType ] , [ ScriptFilePath ] ,
[ NewPhysicalLocation ] , [ Script2Type ] )as String
Parts
object
Expression that evaluates to an object in the Applies To list.ScriptType
Optional. A long integer that overrides default scripting behavior as described in Settings.ScriptFilePath
Optional. A string that specifies an operating system file as an additional target for the generated Transact-SQL script.NewPhysicalLocation
Optional. A string that identifies a device by operating system name and used in place of that locating the scripted device.Script2Type
Optional. A long integer that overrides default scripting behavior as described in Settings.
Prototype (C/C++)
HRESULT Script(
SQLDMO_SCRIPT_TYPE ScriptType = SQLDMOScript_Default,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPCSTR NewPhysicalLocation = NULL,
SQLDMO_LPBSTR ScriptText = NULL,
SQLDMO_SCRIPT2_TYPE Script2Type = SQLDMOScript2_Default);
[!附註]
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
When setting the ScriptType argument specifying multiple behaviors, combine values using an OR logical operator. Use these values to set ScriptType.
Constant |
Value |
Description |
---|---|---|
SQLDMOScript_AppendToFile |
256 |
Object Script method only. Append to indicated output file. By default, Script method overwrites existing file. |
SQLDMOScript_Default |
4 |
SQLDMOScript_PrimaryObject. |
SQLDMOScript_Drops |
1 |
Generate Transact-SQL to remove referenced component. Script tests for existence prior attempt to remove component. |
SQLDMOScript_PrimaryObject |
4 |
Generate Transact-SQL creating the referenced component. |
SQLDMOScript_ToFileOnly |
64 |
Most SQL-DMO object scripting methods specify both a return value and an optional output file. When used, and an output file is specified, the method does not return the script to the caller, but only writes the script to the output file. |
When setting the Script2Type argument specifying multiple behaviors, combine values using an OR logical operator. Use these values to set Script2Type.
Constant |
Value |
Description |
---|---|---|
SQLDMOScript2_AnsiFile |
2 |
Create output file as a multibyte character text file. Code page 1252 is used to determine character meaning. |
SQLDMOScript2_Default |
0 |
Default. No scripting options specified. |
SQLDMOScript2_UnicodeFile |
4 |
Create output file as a Unicode character text file. |
Returns
A Transact-SQL command batch as a string.
備註
The NewPhysicalLocation property is a string with a maximum of 260 characters. Specify an operating system file using a UNC string or drive letter, path, and name. Specify a tape device using a UNC string. For example, the string \\Seattle1\Backups\Northwind.bak specifies a server name, directory, and file name for a backup device. The string \\.\TAPE0 specifies a server and a file device, most likely a tape, as a backup device.
[!附註]
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.