Skip to content

Releases: EitanBlumin/sp_GenerateTableDDLScript

v1.0

02 May 07:21
bc5b7b3
Compare
Choose a tag to compare

sp_GenerateTableDDLScript v1.0

This is the first public release.
For more info please visit our official GitHub page.

License

The sp_GenerateTableDDLScript procedure is licensed under the Mozilla Public License 2.0.

For more info Click Here

Procedure Parameters

@TableName SYSNAME,			-- The name of the source table. This parameter is mandatory. If the table's schema is not default (dbo), then please specify the schema name as well as part of the parameter.
@NewTableName SYSNAME = NULL,		-- The name of the new (target) table. You may also include database and schema as part of the name. If not specified, same name as source table will be used.
@Result NVARCHAR(MAX) OUTPUT,		-- Output textual parameter that will contain the result TSQL command for creating the table.
@IncludeDefaults BIT = 1,		-- Set whether to include default constraints
@IncludeCheckConstraints BIT = 1,	-- Set whether to include check constraints
@IncludeForeignKeys BIT = 1,		-- Set whether to include foreign key constraints
@IncludeIndexes BIT = 1,		-- Set whether to include indexes
@IncludePrimaryKey BIT = 1,		-- Set whether to include primary key constraints
@IncludeIdentity BIT = 1,		-- Set whether to include identity property
@IncludeUniqueIndexes BIT = 1,		-- Set whether to include unique index constraints
@IncludeComputedColumns BIT = 1,	-- Set whether to include computed columns (if not, they will also be automatically ignored by constraints and indexes)
@UseSystemDataTypes BIT = 0,		-- Set whether to use system data type names instead of user data type names
@ConstraintsNameAppend SYSNAME = ''	-- This is an optional text string to append to constraint names, in order to avoid the duplicate object name exception. This is useful when creating the new table within the same database.

Remarks

  • The source table must exist, otherwise an exception will be raised.
  • The script does not check whether the target table already exists,
    it falls on you to make sure that it doesn't before running the result script.
  • The script does not check whether constraint names already exist,
    it falls on you to use the @ConstraintsNameAppend parameter to generate unique names.
  • The script (at the moment) does NOT support the following (more info at the issues page):
    • Column Sets
    • Collations different from Database Default
    • Filestream columns
    • Sparse columns
    • Not for replication property
    • XML document collections
    • Rule objects
    • Non-default Filegroups
    • In-Memory tables

Contribution & Issue Submission

This is an open-source project, and therefore you may freely submit your own issue and pull requests, if you wish to contribute.

Any contribution is welcome.

You may view the currently opened issues at the GitHub Issues page.