Building Data Dictionary using SQL Server 2005

When design a  new system, you can using sql statements blew to build the data dictionary document ,

it's very fast ,the statements can help you  a lot,you just need to copy the result to your excel document.


--build index dictionary

SELECT O.name AS '表名',
I.name AS '索引名称',
(CASE I.type_desc WHEN  'CLUSTERED' THEN '聚集索引' WHEN 'NONCLUSTERED' THEN '非聚聚索引' ELSE '' END ) AS '索引类型',
(CASE SUBSTRING(I.NAME,1, 3) WHEN  'PK_' THEN '主键聚集索引    ' ELSE '' END) AS '描述'
FROM sys.indexes AS I
INNER JOIN sys.objects AS O ON I.object_id = O.object_id
WHERE O.type = 'U'
AND O.name NOT LIKE '%Z_%'
ORDER BY O.name ASC , I.name DESC


--build table and column dictionary

SELECT O.name '表名',
C.name '列名',
(case C.is_nullable WHEN 1 THEN 'yes' ELSE 'no' END ) AS '是否允许为空',
T.name AS '数据类型',
T.max_length AS '数据长度',
D.definition AS '默认值'
FROM sys.objects AS O
INNER JOIN sys.columns AS C ON C.object_id = O.object_id
LEFT JOIN sys.default_constraints AS D ON D.object_id = C.default_object_id AND D.type = 'D'
INNER JOIN sys.types AS T ON C.system_type_id = T.system_type_id AND T.schema_id = 4
WHERE O.type = 'U'


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值