开发者

Script out schema in SQL Server

开发者 https://www.devze.com 2023-02-16 02:50 出处:网络
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

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

  1. 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.
  2. On the Choose Objects page, select the objects to be included in the script. For more information, see Generate Scripts Wizard (Choose Objects Page).
  3. 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).
  4. 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).
  5. 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号