Script Method (BackupDevice Object) (SQL-DMO)

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-DMO object.

Applies To

BackupDevice Object

Syntax

object.Script( [ ScriptType ] , [ ScriptFilePath ] , [ NewPhysicalLocation ]
, [ Script2Type ] ) as String

Part Description
object Expression that evaluates to an object in the Applies To list.
ScriptType Optional. A long integer overriding default scripting behavior as described in Settings.
ScriptFilePath Optional. A string specifying an operating system file as an additional target for the generated Transact-SQL script.
NewPhysical
Location
Optional. A string identifying a device by operating system name and used in place of that locating the scripted device.
Script2Type Optional. A long integer overriding default scripting behavior as described in Settings.

Settings

When setting the ScriptType argument specifying multiple behaviors, combine values by using an Or. Use these values to set ScriptType.

Constant Value Description
SQLDMOScript_AppendToFile 256 Append output to the file identified in the ScriptFilePath argument. By default, Script overwrites an existing file.
SQLDMOScript_Default 4 SQLDMOScript_
PrimaryObject.
SQLDMOScript_Drops 1 Command batch includes Transact-SQL statements removing the referenced component. Transact-SQL statements removing a component are prefixed by a test for existence.
SQLDMOScript_PrimaryObject 4 Default. Command batch includes Transact-SQL statements creating the referenced component.
SQLDMOScript_ToFileOnly 64 When used, and an output file is specified in the ScriptFilePath argument, the Script 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 by using an Or. 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.

Remarks

The NewPhysicalLocation property is a string of up to 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.


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.


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);


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.


  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.