Script out in SQL Server

I want to create a schema in a SQL Server database. The database also has many other scripts. Can I script exit an existing schema? I mean, suppose we have a table, can we script out a CREATE TABLE script? Can we script create a creation scheme.

Thanks guys, pending

+4
source share
2 answers

If you right-click on the node database in SSMS, you can script the whole schema.

See this for reference on MSDN.

Script Creation and Publishing Wizard

Using the script creation and publishing wizard, create a Transact-SQL script for many objects. The wizard creates a script of all the objects in the database or a subset of the selected objects. the wizard has many options for your scenarios, for example, whether to include permissions, mappings, restrictions, etc. For more information, see the Wizard F1 Scripting Wizard Help.

To open the script creation and publishing wizard

  • In Object Explorer, expand Databases, right-click the database, point to Tasks, and then click Generate Scripts. Follow the steps in the wizard for the script database objects.
  • On the Select Objects page, select the objects that will be included in the script. For more information, see "Creating Scripts" (select Object Page).
  • On the Script Set Options page, select Save Scripts for a specific location. To specify advanced script options, select Advanced in the Save scripts in a specific section. a. Select the location of the generated script file: to a file, Engine Query Editor database, or to the clipboard. b. For more information, see "Creating Scripts" (Set Scripting Parameters Page).
  • On the Summary page, review your selection. Click "Previous." change your choice. Click "Next" to create the script objects that you selected. For more information, see Create Scripting Wizard (Summary Page).
  • On the Save or Publish Scripts page, track the progress of the script generation. For more information, see the Scripting Section (Save or Publish a Scripting Page)
+4
source

I wrote an open source command line utility called SchemaZen that does this. This is much faster than scripts from the management studio, and the output is more version friendly. It supports both schema and data scenarios.

To start the script run:

  schemazen.exe script --server localhost --database db --scriptDir c: \ somedir 

Then, to recreate the database from the script run:

  schemazen.exe create --server localhost --database db --scriptDir c: \ somedir 
+3
source

Source: https://habr.com/ru/post/1343366/


All Articles