title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | monikerRange |
---|---|---|---|---|---|---|---|---|---|
Generate Scripts |
Learn how to use the Generate and Publish Scripts Wizard to create Transact-SQL scripts for multiple objects, and how to use the Script as menu in Object Explorer to generate scripts for individual or multiple objects. |
markingmyname |
maghan |
mathoma |
04/07/2020 |
sql |
ssms |
conceptual |
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDESQL Server Azure SQL Database Synapse Analytics PDW]
SQL Server Management Studio provides two mechanisms for generating [!INCLUDEtsql] scripts. You can create scripts for multiple objects by using the Generate and Publish Scripts Wizard. You can also generate a script for individual objects or multiple objects by using the Script as menu in Object Explorer.
For a detailed Tutorial on scripting various objects using SQL Server Management Studio (SSMS), see Tutorial: Scripting in SSMS.
Choose the mechanism that best meets your requirements.
Use the Generate and Publish Scripts Wizard to create a [!INCLUDEtsql] script for many objects. The wizard generates a script of all the objects in a database, or a subset of the objects that you select. The wizard has many options for your scripts, such as whether to include permissions, collation, constraints, and so on. For instructions on using the wizard, see Generate and Publish Scripts Wizard.
You can use the Object Explorer Script as menu to script a single object, script multiple objects, or script multiple statements for a single object. You can choose one of several types of scripts; for example to create, alter, or drop the object. You can save the script in a Query Editor window, to a file, or to the Clipboard. The script is created in Unicode format.
To script a single object
-
In Object Explorer, connect to an instance of the [!INCLUDEssDEnoversion] and then expand that instance.
-
Expand Databases, and then expand the database containing the object to be scripted.
-
Expand the category of the object. For example, expand the Tables or Views node.
-
Right-click the object, point to Script <object type> as, For example, point to Script Table as.
-
Point to the script type, such as Create to or Alter to.
-
Select the location to save the script, such as New Query Editor Window or Clipboard.
You can use the Object Explorer Details pane to generate a script for multiple objects of the same category.
-
In Object Explorer, connect to an instance of the [!INCLUDEssDEnoversion] and then expand that instance.
-
Expand Databases, and then expand the database containing the objects to be scripted.
-
Expand the category node of the types of object you want to script, such as the Tables node.
-
Open the Object Explorer Details pane by either selecting F7, or opening the View menu and selecting Object Explorer Details.
-
Left-click one of the objects you want to script.
-
Ctrl + left-click the second object you want to script.
-
Right-click one of the selected objects, and select Script <object type> as.