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)

Generate DDL script to create table and all constraints

By VPSD Gupta,

Sometimes you quickly need to generate SQL Statements within your SPs or your front-end code to manipulate data in various ways. This SP generates all the SQL Statements of an existing table in a database to create a table, create Primary Key, create various Foreign Keys, create check constraints and create Defaults on every column of a table.

Use the SP by passing the following parameters:

EXEC usp_Create_Table_DDLs @sTable_Name = 'MY_TABLE', @Create_Table_Ind = 1, @PK_Ind = 1, @FK_Ind = 1, @Check_Ind = 1, @Default_Ind = 1

By default all the indicator variables are set to 1 but you can change that to 0 if you don't need the SQL for that.

Total article views: 2200 | Views in the last 30 days: 20
 
Related Articles
FORUM

Default parameters changing when new database is created

Default parameters when database is created with Studio

FORUM

Creating a default user

Is there a way of defaulting a gived SQL login to every database created?

FORUM

User Default Schema Problem

User creates objects in dbo other than the default schema

FORUM

Default Constraint Error

Getting an error while creating a default constraint dynamically

ARTICLE

Stairway to Server-side Tracing - Level 4: How to Create and View Default and black box Trace Data

An introduction to the SQL Server default and black box traces targeted at DBAs who are new to these...

 
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