SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Table Generator for defined tables

By Ryan Foote,


Many times sql developers and dbas are given the task of scripting and standardizing code and checking into a source control system after the objects, in this case tables, are already defined in sql server. This can be achieved by right clicking on the object and then selecting the "Script Table As" option; however, this option creates a file that needs modifcation and proper formatting in most cases. I have taken the time to createa script that generates the create table DDL in a more readable, tabbed format.


How to use

Simply enter the table name in the script where the @TableName paramter is and run. The script will generate the appropriate existence check, the create table statement with datatypes and nullability, any defaults defined, and the primary key definition after the create table statement. The script will account for any compound primary keys with up to 16 columns defined. The script will not explicitly define the collation, so the default defined is used. And, the script currently does handle foreign keys. This should save the user some time and effort for this task.


Total article views: 1825 | Views in the last 30 days: 1
Related Articles

Get the defination of all table type in database

THis script will generate the Drop and create script for all user define table type


How to create Policies using PowerShell scripts

This article explains how to create policies with user defined conditions in MS SQL 2008 using Powe...


Create Login Script

Error with Create Login Script


Creating User-Defined Data Types - SQL School Video

Learn how you can create your own data types in this SQL School video. MVP Andy Warren explains the ...


Generate Drop / Create Script for views, stored Procedures

This Script generates drop and create scripts for views or stored procedures.