Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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,

Introduction

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: 1719 | Views in the last 30 days: 6
 
Related Articles
SCRIPT

Get the defination of all table type in database

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

ARTICLE

How to create Policies using PowerShell scripts

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

FORUM

Create Login Script

Error with Create Login Script

ARTICLE

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

SCRIPT

Generate Drop / Create Script for views, stored Procedures

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

Tags
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones