以下的文章主要是介绍SQL Server数据字典的HTML格式,SQL Server数据字典的HTML格在实际中的应用比例还是占为多数的,如果你对这一技术,心存好奇的话,以下的文章将会揭开它的神秘面纱。
运行下面的脚本来生成数据字典,并保存结果到一个扩展名为“.htm”的文件中。
生成数据字典的示例T-SQL脚本
- Set nocount on
- DECLARE @TableName nvarchar(35)
- DECLARE Tbls CURSOR
- FOR
- Select distinct Table_name
- FROM INFORMATION_SCHEMA.COLUMNS
- --put any exclusions here
- --where table_name not like '%old'
- order by Table_name
- OPEN Tbls
- PRINT ''
- FETCH NEXT FROM Tbls
- INTO @TableName
- WHILE @@FETCH_STATUS = 0
- BEGIN
- PRINT ''
- PRINT '
'
'- Print '' + @TableName + ''
- PRINT ''
- --Get the Description of the table
- --Characters 1-250
- Select substring(cast(Value as varchar(1000)),1,250) FROM
- sys.extended_properties A
- WHERE A.major_id = OBJECT_ID(@TableName)
- and name = 'MS_Description' and minor_id = 0
- --Characters 251-500
- Select substring(cast(Value as varchar(1000)),251, 250) FROM
- sys.extended_properties A
- WHERE A.major_id = OBJECT_ID(@TableName)
- and name = 'MS_Description' and minor_id = 0
- PRINT '
' ',- --Set up the Column Headers for the Table
- PRINT '
Column Name '- PRINT '
Description '- PRINT '
InPrimaryKey '- PRINT '
IsForeignKey '- PRINT '
DataType '- PRINT '
Length '- PRINT '
Numeric Precision '- PRINT '
Numeric Scale '- PRINT '
Nullable '- PRINT '
Computed '- PRINT '
Identity '- PRINT '
Default Value '- --Get the Table Data
- SELECT '
- '
', - '
' + CAST(clmns.name AS VARCHAR(35)) + ' ',- '
' + substring(ISNULL(CAST(exprop.value AS VARCHAR(255)),''),1,250), ',- substring(ISNULL(CAST(exprop.value AS VARCHAR(500)),''),251,250) + '
- '
' + CAST(ISNULL(idxcol.index_column_id, 0)AS VARCHAR(20)) + ' ',- '
' + CAST(ISNULL( ',- (SELECT TOP 1 1
- FROM sys.foreign_key_columns AS fkclmn
- WHERE fkclmn.parent_column_id = clmns.column_id
- AND fkclmn.parent_object_id = clmns.object_id
- ), 0) AS VARCHAR(20)) + '
- '
' + CAST(udt.name AS CHAR(15)) + ' ' ,- '
' + CAST(CAST(CASE WHEN typ.name IN (N'nchar', N'nvarchar') AND clmns.max_length <> -1 ',- THEN clmns.max_length/2
- ELSE clmns.max_length END AS INT) AS VARCHAR(20)) + '
- '
' + CAST(CAST(clmns.precision AS INT) AS VARCHAR(20)) + ' ',- '
' + CAST(CAST(clmns.scale AS INT) AS VARCHAR(20)) + ' ',- '
' + CAST(clmns.is_nullable AS VARCHAR(20)) + ' ' ,- '
' + CAST(clmns.is_computed AS VARCHAR(20)) + ' ' ,- '
' + CAST(clmns.is_identity AS VARCHAR(20)) + ' ' ,- '
' + isnull(CAST(cnstr.definition AS VARCHAR(20)),'') + ' '- FROM sys.tables AS tbl
- INNER JOIN sys.all_columns AS clmns
- ON clmns.object_id=tbl.object_id
- LEFT OUTER JOIN sys.indexes AS idx
- ON idx.object_id = clmns.object_id
- AND 1 =idx.is_primary_key
- LEFT OUTER JOIN sys.index_columns AS idxcol
- ON idxidxcol.index_id = idx.index_id
- AND idxcol.column_id = clmns.column_id
- AND idxcol.object_id = clmns.object_id
- AND 0 = idxcol.is_included_column
- LEFT OUTER JOIN sys.types AS udt
- ON udt.user_type_id = clmns.user_type_id
- LEFT OUTER JOIN sys.types AS typ
- ON typ.user_type_id = clmns.system_type_id
- AND typtyp.user_type_id = typ.system_type_id
- LEFT JOIN sys.default_constraints AS cnstr
- ON cnstr.object_id=clmns.default_object_id
- LEFT OUTER JOIN sys.extended_properties exprop
- ON exprop.major_id = clmns.object_id
- AND exprop.minor_id = clmns.column_id
- AND exprop.name = 'MS_Description'
- WHERE (tbl.name = @TableName and
- exprop.class = 1) --I don't wand to include comments on indexes
- ORDER BY clmns.column_id ASC
- PRINT '
- FETCH NEXT FROM Tbls
- INTO @TableName
- END
- PRINT ''
- CLOSE Tbls
- DEALLOCATE Tbls
这个脚本将被安排作为一个工作来运行,所以你不需要担心要手动更新文档。
因为你将文档存储在数据库中,所以你不必担心拥有多个拷贝并指出哪个是***的。它还会与数据库一起备份。
以上的相关内容就是对HTML格式的SQL Server数据字典 的介绍,望你能有所收获。
本文题目:SQLServer数据字典的HTML格式
URL分享:http://www.csdahua.cn/qtweb/news6/367256.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网