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.
object.Script( [ ScriptType ] [, ScriptFilePath ] [, NewName ] [, 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. |
NewName | Optional. A string specifying a new name for the referenced table. |
Script2Type | Optional. A long integer overriding default scripting behavior as described in Settings. |
When setting the ScriptType argument specifying multiple behaviors, combine values by using a logical 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. |
SQLDMOScript_ClusteredIndexes | 8 | Generate Transact-SQL statements defining clustered indexes. |
SQLDMOScript_Default | 4 | SQLDMOScript_ PrimaryObject |
SQLDMOScript_DRI_All | 532676608 | All values defined as SQLDMOScript_DRI_... combined by using a logical OR. DRI scripting options direct command batch membership when declarative referential integrity establishes dependency relationships. |
SQLDMOScript_DRI_AllConstraints | 520093696 | SQLDMOScript_DRI_ Checks, SQLDMOScript_DRI_ Defaults, SQLDMOScript_DRI_ ForeignKeys, SQLDMOScript_DRI_ PrimaryKey, and SQLDMOScript_DRI_ UniqueKeys combined by using an Or. |
SQLDMOScript_DRI_AllKeys | 469762048 | SQLDMOScript_DRI_ ForeignKeys, SQLDMOScript_DRI_ PrimaryKey, and SQLDMOScript_DRI_ UniqueKeys combined by using an Or. |
SQLDMOScript_DRI_Checks | 16777216 | Command batch includes Transact-SQL statements creating column-specified integrity constraints. |
SQLDMOScript_DRI_Clustered | 8388608 | Command batch includes Transact-SQL statements creating clustered indexes. |
SQLDMOScript_DRI_Defaults | 33554432 | Command batch includes Transact-SQL statements creating column-specified defaults. |
SQLDMOScript_DRI_ForeignKeys | 134217728 | Command batch includes Transact-SQL statements creating FOREIGN KEY constraints. |
SQLDMOScript_DRI_NonClustered | 4194304 | Command batch includes Transact-SQL statements creating creates nonclustered indexes. |
SQLDMOScript_DRI_PrimaryKey | 268435456 | Command batch includes Transact-SQL statements creating PRIMARY KEY constraints. |
SQLDMOScript_DRI_UniqueKeys | 67108864 | Command batch includes Transact-SQL statements creating candidate keys defined using a unique key constraint. |
SQLDMOScript_DRIIndexes | 65536 | When SQLDMOScript_NoDRI is specified, script PRIMARY KEY constraints using a unique index to implement the declarative referential integrity. |
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. |
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. |
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. |
SQLDMOScript_NonClusteredIndexes | 8192 | Command batch includes Transact-SQL statements creating nonclustered indexes. |
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 table, the table name is qualified by the current owner of the referenced table. |
SQLDMOScript_PrimaryObject | 4 | Default. Command batch includes Transact-SQL statements statements creating the referenced component. |
SQLDMOScript4_TimestampToBinary | 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). |
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. |
SQLDMOScript_UDDTsToBaseType | 1024 | Convert specification of user-defined data types to the appropriate SQL Server base data type. |
SQLDMOScript4_UseQuotedIdentifiers | -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. |
SQLDMOScript2_Default | 0 | Default. No scripting options specified. |
SQLDMOScript2_FullTextIndex | 524288 | Command batch includes statements defining Microsoft Search full-text indexing. |
SQLDMOScript2_NoFG | 16 | Command batch does not include ‘ON <filegroup>‘ clause directing filegroup use. |
SQLDMOScript2_NoWhatIfIndexes | 512 | Command batch does not include CREATE STATISTICS statements. |
SQLDMOScript2_UnicodeFile | 4 | Create output file as a Unicode character text file. |
A Transact-SQL command batch as a string.
The Script method generates a Transact-SQL command batch defining an existing SQL Server table. The Table object supports command batch generation when using the object to define a new table. Use the GenerateSQL method when capturing new table definition. Use the Script method when capturing an image of an exiting table. When using the Script method as part of an application process re-creating a table, specify SQLDMOScript_Drops in the ScriptType argument to include a drop of the existing table in the command batch.
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.
HRESULT Script(
SQLDMO_SCRIPT_TYPE ScriptType = SQLDMOScript_Default,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPCSTR NewName = 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.