Compartir a través de


Script 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 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.

Sintaxis

object
.Script( [ ScriptType ] [, ScriptFilePath ] [, 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.
  • 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_LPBSTR ScriptText = NULL,
SQLDMO_SCRIPT2_TYPE Script2Type = SQLDMOScript2_Default);

[!NOTA] 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_/DatabasePermissions

32

Generate Transact-SQL database privilege defining script. Database permissions grant or deny statement execution rights.

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_/IncludeHeaders

131072

Generated script is prefixed with a header containing date and time of generation and other descriptive information.

SQLDMOScript_/IncludeIfNotExists

4096

Transact-SQL creating a component is prefixed by a check for existence. When script is executed, component is created only when a copy of the named component does not exist.

SQLDMOScript_Indexes

73736

SQLDMOScript_ClusteredIndexes, SQLDMOScript_NonClusteredIndexes, and SQLDMOScript_DRIIndexes combined using an OR logical operator. Applies to both table and view objects.

SQLDMOScript_/NoCommandTerm

32768

Individual Transact-SQL statements in the script are not delimited using the connection-specific command terminator. By default, individual Transact-SQL statements are delimited.

SQLDMOScript_/ObjectPermissions

2

Include Transact-SQL privilege defining statements when scripting database objects.

SQLDMOScript_/OwnerQualify

262144

Object names in Transact-SQL generated to remove an object are qualified by the owner of the referenced object. Transact-SQL generated to create the referenced object qualify the object name using the current object owner.

SQLDMOScript_Permissions

34

SQLDMOScript_ObjectPermissions and SQLDMOScript_DatabasePermissions combined using an OR logical operator.

SQLDMOScript_PrimaryObject

4

Generate Transact-SQL creating the referenced component.

SQLDMOScript_/TimestampToBinary

524288

When scripting object creation for a table or user-defined data type, convert specification of timestamp data type to binary(8).

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.

SQLDMOScript_/UseQuotedIdentifiers

-1

Use quote characters to delimit identifier parts when scripting object names.

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_/AgentAlertJob

2048

Generate Transact-SQL script creating SQL Server Agent service jobs and alerts.

SQLDMOScript2_AgentNotify

1024

When scripting an alert, generate script creating notifications for the alert.

SQLDMOScript2_AnsiFile

2

Generated script file uses multibyte characters. Code page 1252 is used to determine character meaning.

SQLDMOScript2_Default

0

No scripting options specified.

SQLDMOScript2_EncryptPWD

128

Encrypt passwords with script. When specified, SQLDMOScript2_UnicodeFile must be specified as well.

SQLDMOScript2_ExtendedProperty

4194304

Include extended property scripting as part of object scripting.

SQLDMOScript2_FullTextCat

2097152

Command batch includes Transact-SQL statements creating Microsoft Search full-text catalogs.

SQLDMOScript2_LoginSID

8192

Include security identifiers for logins scripted.

SQLDMOScript2_MarkTriggers

32

Generated script creates replication implementing triggers as system objects. Applies only when scripting replication articles.

SQLDMOScript2_NoCollation

8388608

Do not script the collation clause if source is later than SQL Server version 7.0. The default is to generate collation.

SQLDMOScript2_UnicodeFile

4

Generated script output file is a Unicode-character text file.

Returns

A Transact-SQL command batch as a string.

Notas

The Script method generates a Transact-SQL command batch that defines an existing SQL Server component. Some SQL-DMO objects, such as the Index object, support command batch generation for SQL-DMO objects that defines new components through the GenerateSQL method.

Use the GenerateSQL method when capturing object definition. Use the Script method when capturing an image of an exiting component. When using the Script method as part of an application process re-creating a component, specify SQLDMOScript_Drops in the ScriptType argument to include a drop of the existing component in the command batch.

[!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.

Applies To:

Alert Object

Jobs Collection

Alerts Collection

Key Object

Check Object

Login Object

Database Object

Operator Object

DatabaseRole Object

Operators Collection

DBObject Object

Rule Object

Default Object

StoredProcedure Object

DRIDefault Object

Trigger Object

FullTextCatalog Object

User Object

Index Object

UserDefinedDatatype Object

Job Object

View Object