快速生成SqlServer数据字典


SELECT   表名 = CASE WHEN A.colorder = 1 THEN D.name ELSE '' END,
         字段序号 = A.colorder,
         字段名 = A.name,
         字段说明 = isnull(G.[value], ''),
         自增 = CASE WHEN COLUMNPROPERTY(A.id, A.name, 'IsIdentity') = 1 THEN '√' ELSE '' END,
         主键 =
           CASE
             WHEN EXISTS
                    (SELECT 1
                     FROM   sysobjects
                     WHERE  xtype = 'PK' AND parent_obj = A.id AND name IN (SELECT name
                                                                            FROM   sysindexes
                                                                            WHERE  indid IN (SELECT indid
                                                                                             FROM   sysindexkeys
                                                                                             WHERE  id = A.id AND colid = A.colid)
                            ))
             THEN
               '√'
             ELSE
               ''
           END,
         类型 = B.name,
         占用字节数 = A.Length,
         长度 = COLUMNPROPERTY(A.id, A.name, 'PRECISION'),
         小数位数 = isnull(COLUMNPROPERTY(A.id, A.name, 'Scale'), 0),
         允许空 = CASE WHEN A.isnullable = 1 THEN '√' ELSE '' END,
         默认值 = isnull(E.Text, '')
FROM     syscolumns A
         LEFT JOIN systypes B ON A.xusertype = B.xusertype
         INNER JOIN sysobjects D ON A.id = D.id AND D.xtype = 'U' AND D.name <> 'dtproperties'
         LEFT JOIN syscomments E ON A.cdefault = E.id
         LEFT JOIN sys.extended_properties G ON A.id = G.major_id AND A.colid = G.minor_id
         LEFT JOIN sys.extended_properties F ON D.id = F.major_id AND F.minor_id = 0
--where d.name='OrderInfo'    --如果只查询指定表,加上此条件
where A.Name not in('CreationTime','CreatorUserId','LastModificationTime','LastModifierUserId','IsDeleted','DeleterUserId','DeletionTime')
ORDER BY A.id, A.colorder

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值