如何在SQL Server 2008中编写数据库脚本?

时间:2022-11-09 08:26:50

I'm trying to export the schema of my database so another developer can have it. On the SQL Server management Studio, if I right click on the database I see a "Script database as" -> "CREATE to" but that generates something like:

我正在尝试导出我的数据库的架构,以便其他开发人员可以拥有它。在SQL Server管理工作室上,如果我右键单击数据库,我会看到“脚本数据库为” - >“创建到”,但生成的内容如下:

...
CREATE DATABASE [Name] ON  PRIMARY 
( NAME = N'Name', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Name.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'Name_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Name_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

instead of the CREATE TABLE statements. How do I get that?

而不是CREATE TABLE语句。我怎么做到的?

3 个解决方案

#1


Use the scripting wizard for that and select all objects. Right click on your database-->tasks-->generate scripts pick DB and check off "script all objects in the selected database".

使用脚本向导,然后选择所有对象。右键单击数据库 - >任务 - >生成脚本选择数据库并选中“编写所选数据库中所有对象的脚本”。

#2


Try this-

Right click on the database, opt for 'Generate Scripts...' under 'Tasks' menu item. This would launch the 'Script Wizard' window. You can then proceed from there as it is very much intuitive.

右键单击数据库,选择'Tasks'菜单项下的'Generate Scripts ...'。这将启动“脚本向导”窗口。然后您可以从那里继续,因为它非常直观。

This would allow you to select all objects in your database and would generate scripts for all of them. Finally the scripts can be saved to a file or viewed in a query editor.

这将允许您选择数据库中的所有对象,并为所有对象生成脚本。最后,脚本可以保存到文件中或在查询编辑器中查看。

cheers

#3


Under Tasks->Generate Scripts

在Tasks-> Generate Scripts下

#1


Use the scripting wizard for that and select all objects. Right click on your database-->tasks-->generate scripts pick DB and check off "script all objects in the selected database".

使用脚本向导,然后选择所有对象。右键单击数据库 - >任务 - >生成脚本选择数据库并选中“编写所选数据库中所有对象的脚本”。

#2


Try this-

Right click on the database, opt for 'Generate Scripts...' under 'Tasks' menu item. This would launch the 'Script Wizard' window. You can then proceed from there as it is very much intuitive.

右键单击数据库,选择'Tasks'菜单项下的'Generate Scripts ...'。这将启动“脚本向导”窗口。然后您可以从那里继续,因为它非常直观。

This would allow you to select all objects in your database and would generate scripts for all of them. Finally the scripts can be saved to a file or viewed in a query editor.

这将允许您选择数据库中的所有对象,并为所有对象生成脚本。最后,脚本可以保存到文件中或在查询编辑器中查看。

cheers

#3


Under Tasks->Generate Scripts

在Tasks-> Generate Scripts下