问题
我需要一个创建能够保持最新数据字典的方法。我对数据库做了很多更改,而我花费于数据 库文档更新的时间多于数据库管理的时间。
专家解答
如果你将元数据存储为扩展属性, 那么你可以使用SQL Server 2005在几秒之内为一个数据库创建一个数据字典。SQL Server 2005 AdventureWorks示例数据库包含了众多扩展属性,所以这个数据库是一个很好的示例。在这篇文章里, 我们将介绍两个核心内容。首先是一组脚本示例,它为表和字段添加扩展属性。其次是生成HTML格式数 据字典的T-SQL代码。
示例脚本——sys.sp_addextendedproperty
下面是一个 示例脚本,它添加扩展属性到这个数据库上。
为表和字段添加扩展属性
/**********
The following extended properties already exist in the AdventureWorks database. There is no need to run the script against the database in order for the remaining samples to work.
**********/
USE [AdventureWorks]
GO
--Script to add an Extended Property to the Table
EXEC sys.sp_addextendedproperty
@name=N'MS_Description',
@value=N'Street address information for customers, employees, and vendors.' ,
@level0type=N'SCHEMA',
@level0name=N'Person', --Schema Name
@level1type=N'TABLE',
@level1name=N'Address' --Table Name
GO
--Script to add an Extended Property to a column
EXEC sys.sp_addextendedproperty
@name=N'MS_Description',
@value=N'First street address line.' ,
@level0type=N'SCHEMA',
@level0name=N'Person', --Schema Name
@level1type=N'TABLE',
@level1name=N'Address',--Table Name
@level2type=N'COLUMN',
@level2name=N'AddressLine1'--Column Name
GO
还可以通过右键单击SSMS中的对象并选择属性来查看扩展属性,如下图所示:
如果你 的数据库在扩展属性中有数据,那么你可以运行查询来提取这个数据。在SQL Server管理套件中,选择 Tools | Options,并在Results to Text中不选“Include column headers in the result set”(在结果集中包含字段头)选项。这将使显示在每个字段名称下面的结果集都不包含字段头。
(编辑:滁州站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|