Script out schema in SQL Server
I want to create a schema in SQL Server database. There are also bunch of other scripts in the database. Can I script out an existing schema? I mean, suppose we have a table, we can
script开发者_高级运维 out a CREATE TABLE
script? Can we script out a Create Schema.
Thanking You Guys in Anticipation,
I wrote an open source command line utility named SchemaZen that does this. It's much faster than scripting from management studio and it's output is more version control friendly. It supports scripting both schema and data.
To generate scripts run:
schemazen.exe script --server localhost --database db --scriptDir c:\somedir
Then to recreate the database from scripts run:
schemazen.exe create --server localhost --database db --scriptDir c:\somedir
If you right click on the database node in SSMS, you can script the whole schema.
See this how-to on MSDN.
Generate and Publish Scripts Wizard
Use the Generate and Publish Scripts Wizard to create a Transact-SQL 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 more information, see Generate Scripts Wizard F1 Help.
To open the Generate and Publish 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.
- On the Choose Objects page, select the objects to be included in the script. For more information, see Generate Scripts Wizard (Choose Objects Page).
- On the Set Scripting Options page, select Save scripts to a specific location. To specify advanced scripting options, select the Advanced button in the Save scripts to a specific location section. a.Select the location for the generated script: to a file, a Database Engine Query Editor window, or the Clipboard. b. For more information, see Generate Scripts Wizard (Set Scripting Options Page).
- On the Summary page, review your selections. Click Previous to change your selections. Click Next to generate a script of the objects you selected. For more information, see Generate Scripts Wizard (Summary Page).
- On the Save or Publish Scripts page, monitor the progress of the script generation. For more information, see Generate Scripts Wizard (Save or Publish Scripts Page)
精彩评论