ScriptDestinationObject Method (SQL-DMO)

The ScriptDestinationObject method generates a Transact-SQL command batch that can be used to create the replicated image of the database object published by the referenced replication article.

Applies To
MergeArticle Object TransArticle Object

Syntax

object.ScriptDestinationObject( [ ScriptType ] , [ ScriptFile ] , [ 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.
ScriptFile Optional. A string specifying an operating system file as an additional target for the generated Transact-SQL script.
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_Bindings 128 Generate sp_bindefault and sp_bindrule statements. Use when the article publishes a table.
SQLDMOScript_ClusteredIndexes 8 Generate Transact-SQL statements defining clustered indexes. Use when the article publishes a table.
SQLDMOScript_Default 4 SQLDMOScript_
PrimaryObject
SQLDMOScript_DRI_All 532676608 All values defined as SQLDMOScript_DRI_... combined by an Or. DRI scripting options direct command batch membership when declarative referential integrity establishes dependency relationships. Use when the article publishes a table.
SQLDMOScript_DRI_
4AllConstraints
520093696 SQLDMOScript_DRI_
Checks, SQLDMOScript_DRI_
Defaults, SQLDMOScript_DRI_
ForeignKeys, SQLDMOScript_DRI_
PrimaryKey, and SQLDMOScript_DRI_
UniqueKeys combined by using an Or. Use when the article publishes a table.
SQLDMOScript_DRI_AllKeys 469762048 SQLDMOScript_DRI_
ForeignKeys, SQLDMOScript_DRI_
PrimaryKey, SQLDMOScript_DRI_
UniqueKeys combined by using an Or. Use when the article publishes a table.
SQLDMOScript_DRI_Checks 16777216 Command batch includes Transact-SQL statements creating column-specified integrity constraints. Use when the article publishes a table.
SQLDMOScript_DRI_Clustered 8388608 Command batch includes Transact-SQL statements creating clustered indexes. Use when the article publishes a table.
SQLDMOScript_DRI_Defaults 33554432 Command batch includes Transact-SQL statements creating column-specified defaults. Use when the article publishes a table.
SQLDMOScript_DRI_ForeignKeys 134217728 Command batch includes Transact-SQL statements creating FOREIGN KEY constraints. Use when the article publishes a table.
SQLDMOScript_DRI_
NonClustered
4194304 Command batch includes Transact-SQL statements creating creates nonclustered indexes. Use when the article publishes a table.
SQLDMOScript_DRI_PrimaryKey 268435456 Command batch includes Transact-SQL statements creating PRIMARY KEY constraints. Use when the article publishes a table.
SQLDMOScript_DRI_UniqueKeys 67108864 Command batch includes Transact-SQL statements creating candidate keys defined using a UNIQUE constraint. Use when the article publishes a table.
SQLDMOScript_DRIIndexes 65536 When SQLDMOScript_NoDRI is specified, script PRIMARY KEY constraints using a unique index to implement the declarative referential integrity. Use when the article publishes a table.
SQLDMOScript_DRIWithNoCheck 536870912 When using SQLDMOScript_DRI_
Checks, or SQLDMOScript_DRI_
ForeignKeys, command batch Transact-SQL statements includes the WITH NOCHECK clause optimizing constraint creation. Use when the article publishes a table.
SQLDMOScript_Drops 1 Command batch includes Transact-SQL statements removing the referenced component. Transact-SQL statements removing a component is prefixed by a test for existence.
SQLDMOScript_IncludeHeaders 131072 Command batch statements are prefixed by a Transact-SQL statements comment containing date and time of generation and other descriptive information.
SQLDMOScript_
IncludeIfNotExists
4096 Transact-SQL statements creating a component is prefixed by a check for existence. When the command batch is executed, the scripted component is created only when a copy does not exist.
SQLDMOScript_Indexes 73736 SQLDMOScript_
ClusteredIndexes, SQLDMOScript_
NonClusteredIndexes, and SQLDMOScript_
DRIIndexes combined by using an Or. Use when the article publishes a table.
SQLDMOScript_
NoCommandTerm
32768 Individual Transact-SQL statements statements in the command batch are not delimited using the connection-specific command terminator. By default, individual Transact-SQL statements statements are delimited.
SQLDMOScript_NoDRI 512 Command batch does not include Transact-SQL statements defining declarative referential integrity constraints. Only use when script will execute on a version 4.21a SQL Server installation.
SQLDMOScript_NoIdentity 1073741824 Command batch does not include Transact-SQL statements defining an identity property, seed, and increment. Use when the article publishes a table.
SQLDMOScript_
4NonClusteredIndexes
8192 Command batch includes Transact-SQL statements creating nonclustered indexes. Use when the article publishes a table.
SQLDMOScript_
ObjectPermissions
2 Command batch includes Transact-SQL statements statements defining privilege on database objects.
SQLDMOScript_OwnerQualify 262144 When the command batch removes or creates a database object, the object name is qualified by the current owner of the referenced object.
SQLDMOScript_PrimaryObject 4 Default. Command batch includes Transact-SQL statements statements creating the referenced component.
SQLDMOScript_4TimestampTo
Binary
524288 When command batch Transact-SQL statements creates a table, a type derived from timestamp is scripted to use the base data type binary(8). Use when the article publishes a table.
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.
SQLDMOScript_Triggers 16 Command batch includes Transact-SQL statements creating triggers. Use when the article publishes a table.
SQLDMOScript_4UDDTsToBase
Type
1024 Convert specification of user-defined data types to the appropriate SQL Server base data type.
SQLDMOScript_4UseQuoted
Identifiers
-1 Quote characters delimit identifier parts when scripting object names.

When setting the Script2Type argument specifying multiple behaviors, combine values by using a logical 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_AnsiPadding 1 Command batch includes Transact-SQL statements SET ANSI_PADDING ON and SET ANSI_PADDDING OFF statements before and after CREATE TABLE statements in the generated script. Use when the article publishes a table.
SQLDMOScript2_Default 0 Default. No scripting options specified.
SQLDMOScript2_FullTextIndex 524288 Command batch includes statements defining Microsoft Search full-text indexing. Use when the article publishes a table.
SQLDMOScript2_NoFG 16 Command batch does not include ‘ON <filegroup>‘ clause directing filegroup use. Use when the article publishes a table.
SQLDMOScript2_NoWhatIf
Indexes
512 Command batch does not include CREATE STATISTICS statements. Use when the article publishes a table.
SQLDMOScript2_UnicodeFile 4 Create output file as a Unicode character text file.

Returns

A Transact-SQL command batch as a string.

Remarks

For SQL-DMO objects publishing replicable database objects, SQL-DMO implements the ScriptDestinationObject method to generate command batches that re-create the objects replicated.


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 version 7.0. Where they are provided, you can use optional scripting arguments, such as SQLDMOScript2_NoFG to remove some 7.0 specific syntax.


Prototype (C/C++)

HRESULT ScriptDestinationObject(
SQLDMO_SCRIPT_TYPE ScriptType = SQLDMOScript_Default,
SQLDMO_LPCSTR ScriptFilePath = 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.