How to: Generate a Script (SQL Server Management Studio)
You can create scripts using the Generate SQL Server Scripts Wizard, or using Object Explorer.
Generate SQL Server Scripts Wizard
The Generate Scripts Wizard walks you through the process of creating scripts, and allows you to select a variety of objects to be scripted at once. The wizard has a variety of options for your scripts, including, such as whether to include permissions, collation, constraints, etc. Use the Wizard when creating scripts for a large number of objects. For information on the Generate SQL Server Scripts Wizard, see Generate SQL Server Scripts Wizard F1 Help.
To open the Generate Scripts Wizard
In Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Generate Scripts.
Follow the steps in the wizard to script the database objects.
Use Object Explore to quickly create scripts of an entire database, or a single database object using the default options. You can create the script in a Query Editor window, to a file, or to the clipboard.
You can create scripts to create or delete the objects. Some object types have additional scripting options, such as ALTER, SELECT, INSERT, UPDATE, DELETE, and EXECUTE.
Sometimes you want a script with multiple options, such as drop a procedure and then create a procedure, or create a table then alter a table. To create combined scripts, save the first script to a Query Editor window and the second to the clipboard so you can paste it into the window after the first script.
To script an object, expand Object Explorer and locate the object. Right-click the object and then click Script <object type> as.
To generate a script of an entire database
In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.
Expand Databases, right-click any database, point to Tasks, point to Generate Scripts, and then follow the steps in the Generate Scripts Wizard.