本文介绍了在SQL Server中生成** bare ** CREATE TABLE和CREATE PROC statemnts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司中的部署程序需要用于创建过程和表等的SQL脚本。



在SQL Server中生成创建脚本管理Studio明显超过一个裸脚本,这是不幸的在这种情况下。例如,对于测试表,这是SSMS为我生成的:

  USE [DemoDB] 
GO

/ ******对象:Table [dbo]。[example]脚本日期:08/07/2012 15:46:32 ****** /
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo]。[example](
[fake_row] [int] NULL
)ON [PRIMARY]

GO

所以,我想知道的是:



我可以以某种方式在SSMS中的SQL Server上运行一个查询,这将给我一个脚本只是以下?

 创建表示例(
fake_row int


解决方案

对自我答案抱歉,标示其他好的答案+1。

事实证明,你可以使用SSMS中的实用程序。


  1. 在对象浏览器中右键点击数据库

  2. 点击任务

  3. 点击生成脚本 li>
  4. 选择脚本特定对象并选择表格或任何其他

  5. 选择保存到文件

  6. 点击高级,您可以启用/禁用您生成的语句的几乎所有部分,包括约束,使用语句等。

  7. 如果需要进一步删除(例如删除GO),这是最少的


The deployment procedures in my company require that SQL scripts for creation of procedures and tables, etc. be bare.

Generating create scripts in SQL Server Management Studio gives you significantly more than a bare script, which is unfortunate in this case. For example, for a test table this is what SSMS generated for me:

USE [DemoDB]
GO

/****** Object:  Table [dbo].[example]    Script Date: 08/07/2012 15:46:32 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[example](
    [fake_row] [int] NULL
) ON [PRIMARY]

GO

So, what I'd like to know is:

Can I somehow run a query on SQL Server in SSMS that would give me a script that was literally just the following?

create table example (
    fake_row int
)
解决方案

Apologies for the self-answer, marking other good answers +1.

It turns out you can get pretty much all of the way there with utility in SSMS.

  1. Right click on the database in the object explorer
  2. Click "Tasks"
  3. Click "Generate Scripts"
  4. Select "Script Specific Objects" and choose tables, or whatever else
  5. Select "Save To File" & "Single File Per Object" (or just spool to query window)
  6. Click "Advanced" and you can enable/disable the generation of virtually every part of the statements you're generating including constraints, use statements, etc.
  7. If further removal is required (e.g. removing GO), it's minimal

这篇关于在SQL Server中生成** bare ** CREATE TABLE和CREATE PROC statemnts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:17