You can use the Generate Script As command in Object Viewer to create scripts and templates from:
To open Object Viewer, select View > Object Viewer or press F7.

1. In Database Explorer, click the folder with a database object you want to generate the script for. It automatically appears in Object Viewer.
2. On the Object Viewer toolbar, click Properties to open the properties grid.

3. In the properties grid, right-click the object you want to generate a script for.
Tip
To select a range of objects, click the first object, hold Shift, and click the last object.
To select individual objects, hold down Ctrl and click each object you want to include.
4. Select Generate Script As, and then choose the type of statement you want to generate.
5. Select the output format for the script:
To New SQL Window – Opens the script in a new SQL window.
To File – Saves the script as a SQL file.
To Clipboard – Copies the script to the clipboard.

The following example shows the generated CREATE script that is opened in a new SQL window:

1. In Database Explorer, click the folder with a database object containing the data you want to generate the script for. It automatically appears in Object Viewer.
2. In Object Viewer, double-click the required object to open it.

3. On the Object Viewer toolbar, click Data to open Data Viewer.

4. In Data Viewer, select the data values for which you want to generate a script.
Tip
To select a range of data, click the first cell, hold Shift, and click the last cell. You can also click and drag while holding the left mouse button.
To select individual cells, hold down Ctrl and click each cell you want to include.
5. Right-click the selection and select Generate Script As, and then choose the type of statement you want to generate.
6. Select the output format for the script:
To New SQL Window – Opens the script in a new SQL window.
To File – Saves the script as a SQL file.
To Clipboard – Copies the script to the clipboard.

The following example shows the generated UPDATE script that is opened in a new SQL window:

Note
You can generate scripts for a large number of objects or the entire database using one of the following options:
- To create a scripts folder or a database snapshot, see How to create a scripts folder or a snapshot.
- To generate scripts for multiple objects or the entire database, see How to generate SQL Server database scripts.