sql server 架构

描述 (Description)

We often have a need to view object definitions in SQL Server, whether they be tables, triggers, or foreign keys. The built in tools are great for an object here and there, but are very cumbersome if you’re looking to generate create statements for a large number of objects.

我们经常需要在SQL Server中查看对象定义,无论它们是表,触发器还是外键。 内置工具非常适合在这里和那里的对象,但是如果您要为大量对象生成create语句,则它们非常麻烦。

We will be introducing (and reintroducing) many different system views that provide valuable information about objects within SQL Server. This will allow us to understand how to locate and use information about our data and then be able to perform extremely useful tasks, such as creating copies of our schema, validating correctness, or generating schema for testing purposes.

我们将介绍(并重新引入)许多不同的系统视图,这些视图提供有关SQL Server中对象的有价值的信息。 这将使我们了解如何查找和使用有关我们数据的信息,然后能够执行极其有用的任务,例如创建架构的副本,验证正确性或生成用于测试目的的架构。

背景和目的 (Background and Purpose)

Being able to quickly display the CREATE statement for an object can be extremely useful. Not only does this allow us to review our database schema, but it allows us to use that information to build out copies of some or all of those structures. Why would we ever want to do this? There are many good reasons, some of which I’ll list here:

能够快速显示对象的CREATE语句非常有用。 这不仅使我们可以查看数据库架构,还可以使我们使用该信息来构建某些或所有这些结构的副本。 我们为什么要这样做? 有很多好的理由,我将在这里列出其中的一些理由:

  • Quickly view the definition of a single object. 快速查看单个对象的定义。
  • Automated Schema Validation 自动化架构验证
  • Generate a creation script, to be used to build those objects elsewhere. 生成创建脚本,以用于在其他位置构建那些对象。
  • Use the creation scripts from multiple databases in order to compare/contrast objects. 使用来自多个数据库的创建脚本来比较/对比对象。
  • View all objects within a table in a single script. 在单个脚本中查看表中的所有对象。
  • View all or some objects in a database based on customized input. 根据自定义输入查看数据库中的全部或某些对象。
  • Generate creation scripts for use in source control. 生成用于源代码管理的创建脚本。

SQL Server Management Studio allows you to right-click on any object that is viewable from the database tree and choose to generate a create statement from it, like this:

SQL Server Management Studio允许您右键单击在数据库树中可见的任何对象,然后选择从中生成一个create语句,如下所示:

The resulting TSQL is as follows:

生成的TSQL如下:


USE [AdventureWorks2014]
GO/****** Object:  Table [Person].[Address]    Script Date: 5/8/2016 3:48:12 PM ******/
SET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOCREATE TABLE [Person].[Address]([AddressID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,[AddressLine1] [nvarchar](60) NOT NULL,[AddressLine2] [nvarchar](60) NULL,[City] [nvarchar](30) NOT NULL,[StateProvinceID] [int] NOT NULL,[PostalCode] [nvarchar](15) NOT NULL,[SpatialLocation] [geography] NULL,[rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,[ModifiedDate] [datetime] NOT NULL,CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED
([AddressID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]GOALTER TABLE [Person].[Address] ADD  CONSTRAINT [DF_Address_rowguid]  DEFAULT (newid()) FOR [rowguid]
GOALTER TABLE [Person].[Address] ADD  CONSTRAINT [DF_Address_ModifiedDate]  DEFAULT (getdate()) FOR [ModifiedDate]
GOALTER TABLE [Person].[Address]  WITH CHECK ADD  CONSTRAINT [FK_Address_StateProvince_StateProvinceID] FOREIGN KEY([StateProvinceID])
REFERENCES [Person].[StateProvince] ([StateProvinceID])
GOALTER TABLE [Person].[Address] CHECK CONSTRAINT [FK_Address_StateProvince_StateProvinceID]
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key for Address records.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'AddressID'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'First street address line.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'AddressLine1'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Second street address line.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'AddressLine2'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Name of the city.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'City'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Unique identification number for the state or province. Foreign key to StateProvince table.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'StateProvinceID'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Postal code for the street address.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'PostalCode'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Latitude and longitude of this address.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'SpatialLocation'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'rowguid'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Default constraint value of NEWID()' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'CONSTRAINT',@level2name=N'DF_Address_rowguid'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date and time the record was last updated.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'ModifiedDate'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Default constraint value of GETDATE()' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'CONSTRAINT',@level2name=N'DF_Address_ModifiedDate'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Street address information for customers, employees, and vendors.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key (clustered) constraint' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'CONSTRAINT',@level2name=N'PK_Address_AddressID'
GOEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Foreign key constraint referencing StateProvince.StateProvinceID.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'CONSTRAINT',@level2name=N'FK_Address_StateProvince_StateProvinceID'
GO

Wow…that is quite a bit of output for a single table. If all we needed was some information about this table, and we didn’t mind the extra output, then this would generally be adequate. If we were looking for schema creation scripts for an entire schema, database, or some other large segment of objects, then this approach would become cumbersome. Right-clicking a hundred times is not my idea of fun, nor is it something that can be easily automated.

哇...对于单个表来说,这是相当多的输出。 如果我们只需要有关此表的一些信息,而我们不介意多余的输出,则通常就足够了。 如果我们正在寻找用于整个模式,数据库或对象的其他较大部分的模式创建脚本,那么这种方法将变得很麻烦。 右键单击一百遍不是我的乐趣,也不是可以轻松自动化的东西。

Some of the output can be customized. For example, if I wanted to turn off the scripting of extended properties, I could do so via the SSMS options as follows:

一些输出可以定制。 例如,如果我想关闭扩展属性的脚本,可以通过如下的SSMS选项关闭:

While this menu allows for quite a bit of customization of scripting output, the idea of having to return to this menu whenever I would like to change what I am outputting does seem a bit slow. While clicking through menus is easy, it’s slow and manual, both attributes I don’t generally like to incorporate into my workday

sql server 架构_在SQL Server中引入架构文档相关推荐

  1. java word 纸张大小_如何在Java中为Word文档(.doc或.docx)设置背景色(页面颜色)?...

    通过诸如http://poi.apache.org之类的某些库,我们可以创建具有任何文本颜色的 Word文档 ,但是对于文本的 背景 或突出显示,我没有找到任何解决方案. 页面颜色以手动方式显示!: ...

  2. java word 颜色设置_如何在Java中为word文档(.doc或.docx)设置背景颜色(页面颜色)?...

    通过像http://poi.apache.org这样的库,我们可以用任何文本颜色创建word文档,但是对于文本的背景或突出显示,我没有找到任何解决方案. 手动方式的单词页面颜色!: 这是我通过poi. ...

  3. word文档打印预览有阴影_在打印预览中编辑Word文档

    word文档打印预览有阴影 While viewing a Word document in the Print Preview window, you might notice a typo, or ...

  4. wps如何在目录里面打省略号_在wps中怎么让文档目录的省略号对齐 - 卡饭网

    怎么在WPS中快速统计文档字数? 怎么在WPS中快速统计文档字数? 相信很多小伙伴在日常办公中都有用到WPS,在其中如何才能统计文档字数呢?方法很简单,下面小编就来为大家介绍.具体如下:1. 首先,打 ...

  5. word2013插入excel对象报错_使用Excel中的插入对象功能在Excel中插入Word文档

    使用Excel中的插入对象功能在Excel中插入Word文档 时间:2016-05-17   作者:snow   来源:互联网 使用Excel中的插入对象功能,就可以很容易地在Excel中插入Word ...

  6. jquery文档就绪_在jQuery中,下列关于文档就绪函效的写法错误的是( )

    [单选题]下图是哪种辉石.() [单选题]人体的肌肉主要是由蛋白质构成的,但骨骼肌.心肌.平滑肌的功能各不相同,这是因为 ( ) [判断题]宝石级方柱石首次发现于缅甸. [判断题]市场上最主要的辉石品 ...

  7. WPF中使用流文档灵活地显示内容

    WPF中使用流文档灵活地显示内容                             by: Markus Egger                             form: http ...

  8. jsqlparser 简介、中文文档、中英对照文档 下载

    jsqlparser 文档 下载链接(含jar包.源码.pom) 组件名称 中文-文档-下载链接 中英对照-文档-下载链接 jsqlparser-0.9.5.jar jsqlparser-0.9.5- ...

  9. mybatis 简介、中文文档、中英对照文档 下载

    mybatis 文档 下载链接(含jar包.源码.pom) 组件名称 中文-文档-下载链接 中英对照-文档-下载链接 mybatis-3.2.8.jar mybatis-3.2.8-API文档-中文版 ...

  10. PageOffice如何控制在系统中打开Word文档只读

    PageOffice如何控制在系统中打开Word文档只读 在文档系统有些环节需要限制用户编辑word文件,只许查看,那么如何实现用程序控制文件打开的时候,用只读模式打开呢?若通过PageOffice开 ...

最新文章

  1. 就是这么霸道,使用OpenCV10行代码实现人脸检测
  2. python数据库模块_十二、Python高级功能之Mysql数据库模块
  3. bat 快速切换路径
  4. Android动画之Tween动画实战
  5. BigData之Hadoop:Hadoop的简介、深入理解、下载、案例应用之详细攻略
  6. ActiveMQ的集群与高可用
  7. [转]IIS的完整控制类
  8. Unionid-微信开发学习
  9. grafana-----Time Range Controls
  10. iOS底层探索之对象的本质和类的关联特性initIsa(上)
  11. hackrf+portapack 组装上手体验记录
  12. java 仓库管理系统源码
  13. java如何调用百度地图拾取坐标系统
  14. 深入探究:TIFF格式的影像如何转jpg (保持色彩不变)
  15. dockerfile的端口映射
  16. php 0x80070005,FastCGI Error Number: 5 (0x80070005)解决方法
  17. 忘记 Apple ID 密码?重设 Apple ID 密码的 3 种方法
  18. Power BI与Tableau的对比与选择
  19. 如何ssh连接本地的虚拟机
  20. java输出华氏摄氏温度转换表_C语言入门教程-示例:编写能够打印华氏-摄氏温度转换表的程序...

热门文章

  1. dayz如何修改服务器指令,【遊戲本體內核心代碼修改】DayZ 有無控制臺刷物品指令、Or設定服務端刷物品MOD...
  2. java正方形矩阵_已知一个NxN的矩阵A,求矩阵中所有边长为m的正方形的子矩阵
  3. 百度微软云服务器地址,win10的ie浏览器默认地址被百度劫持
  4. JavaScript中的流程控制
  5. flask-uploads扩展的使用笔记
  6. 【转】Oracle DECODE函数的语法介绍
  7. react-router-dom系列之-codesandbox
  8. Unity通过键盘按键控制小球移动
  9. Error: Cannot create file “D:xampp\xampp-controlin“.拒绝访问。
  10. HTML+CSS制作3D旋转相册