How to Generate DDL Scripts(Create) from SQL Server Management Studio (SSMS) - SQL Server / TSQL Tutorial Part 17


We often need to get DDL( Data Definition Language) scripts for different objects such as tables, views and Stored Procedures etc.
Is it possible to generate Create Table statement for a table in SSMS?
If I need to generate Create statement for all the tables/view, Will SSMS let me do it?


Generate Script for Single Object:

SQL Server Management Studio ( SSMS) does provide the feature to script single or all objects. To generate DDL script for single object, You can right click on the object and then choose the statement you like to create. Let's say if we would like to generate create table statement for existing table, we will choose below options.

How to generate DDL script ( Create Table) for an object in SSMS - SQL Server Tutorial

How to Generate DDL Scripts for More than One Object:
This is also easy. You need to Right click on the Database in which the objects exists. Then go to Tasks and hit Generate Scripts.

How to generate scripts for multiple objects in SSMS - SQL Server Tutorial

In Next window, you will be able to choose the objects for which you would like to create script. 

Generate Scripts for all the objects in a Database by using SQL Server Management Studio ( SSMS)

The next window will ask you if you like to have the scripts open in new Query Window or you would like to save in a file. Sometime you have a lot of objects and those script might not fit in Query Window, you can always save to file and then use it when required.

How to script all tables/Views/Stored Procedures from a database in SQL Server

Once you hit Next, You will see the progress windows as shown below. Once done. You can hit Finish. 
SQL Server Management Studio- How to script all objects in SSMS

No comments:

Post a Comment