Generate Database Script In SQL Server

In SQL Server Management Studio we have option of generating Transact-SQL scripts for multiple objects or for an individual object by using the Generate and Publish Scripts Wizard.

We can save full database into a single text file related to queries for future uses like self-Practicing, Training to others, source code saving for development work or for backup purposes, etc.

Script generation of Individual Object can be possible as in the following,

Right click on a selected Table then select Script Table as option, further select script query option and click on File option to save text file on a selected location.
a2


Now for Database Script Generation: Select the Database first, here I’m selecting Trainee as a Database, then select Tasks. Now click on Generate Scripts as in the following,


a1


Now click on Next and a new Wizard will open as in the following,

g3


You can select option of Script Entire Database Objects or you can specify database objects for script generation like Table, Views, Stored Procedure or Functions.


g4


I clicked on Entire database and pressed Next, A window will be displayed as shown below, Provide file saving Path/Destination.

g5


Click on Next now: It will open a window with Review Your Selections options:

g6

Now press on Next: Saving Scripts Confirmation actions will be displayed and press Finish to close window.


g7


Similar Articles