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

preview_player
Показать описание
How to Generate DDL Scripts(Create) from SSMS - SQL Server / T-SQL Tutorial

Scenario:

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?

Solution:

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

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

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.

Once you hit Next, You will see the progress windows as shown below. Once done. You can hit Finish.

Check out our website for Different SQL Server, MSBI tutorials and interview questions
such as SQL Server Reporting Services(SSRS) Tutorial
SQL Server Integration Services(SSIS) Tutorial
SQL Server DBA Tutorial
SQL Server / TSQL Tutorial ( Beginner to Advance)
Рекомендации по теме
Комментарии
Автор

Thanks for sharing. How do you save the file/query as a .DDL?

Groovechild
Автор

Hi, Is there any way I can do this through sql query instead of wizard

aashna
join shbcf.ru