在SQL Server中生成** bare ** CREATE TABLE和CREATE PROC statemnts

编程入门 行业动态 更新时间:2024-10-22 14:28:30
本文介绍了在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中的实用程序。

  • 在对象浏览器中右键点击数据库
  • 点击任务
  • 点击生成脚本 li>
  • 选择脚本特定对象并选择表格或任何其他
  • 选择保存到文件
  • 点击高级,您可以启用/禁用您生成的语句的几乎所有部分,包括约束,使用语句等。
  • 如果需要进一步删除(例如删除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.

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

    在SQL Server中生成** bare ** CREATE TABLE和CREATE PROC statemnts

    本文发布于:2023-10-07 14:20:26,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1469625.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:bare   Server   SQL   CREATE   statemnts

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!