数据库字典查询
时间:2021-07-01 10:21:17
帮助过:3人阅读
SELECT 表名
= CASE WHEN a.colorder
= 1 THEN d.name
2 ELSE ‘‘
3 END ,
4 表说明
= CASE WHEN a.colorder
= 1 THEN ISNULL(f.value,
‘‘)
5 ELSE ‘‘
6 END ,
7 字段序号
= a.colorder ,
8 字段名
= a.name ,
9 标识
= CASE WHEN COLUMNPROPERTY(a.id, a.name,
‘IsIdentity‘)
= 1 THEN ‘√‘
10 ELSE ‘‘
11 END ,
12 主键
= CASE WHEN EXISTS (
SELECT 1
13 FROM sysobjects
14 WHERE xtype
= ‘PK‘
15 AND name
IN (
16 SELECT name
17 FROM sysindexes
18 WHERE indid
IN (
19 SELECT indid
20 FROM sysindexkeys
21 WHERE id
= a.id
22 AND colid
= a.colid ) ) )
23 THEN ‘√‘
24 ELSE ‘‘
25 END ,
26 类型
= b.name ,
27 占用字节数
= a.length ,
28 长度
= COLUMNPROPERTY(a.id, a.name,
‘PRECISION‘) ,
29 小数位数
= ISNULL(
COLUMNPROPERTY(a.id, a.name,
‘Scale‘),
0) ,
30 允许空
= CASE WHEN a.isnullable
= 1 THEN ‘√‘
31 ELSE ‘‘
32 END ,
33 默认值
= ISNULL(e.
text,
‘‘) ,
34 字段说明
= ISNULL(g.
[value],
‘‘)
35 FROM syscolumns a
36 LEFT JOIN systypes b
ON a.xtype
= b.xusertype
37 INNER JOIN sysobjects d
ON a.id
= d.id
38 AND d.xtype
= ‘U‘
39 AND d.name
<> ‘dtproperties‘
40 LEFT JOIN syscomments e
ON a.cdefault
= e.id
41 LEFT JOIN sys.extended_properties g
ON a.id
= g.major_id
42 AND a.colid
= g.minor_id
43 LEFT JOIN sys.extended_properties f
ON d.id
= f.major_id
44 AND f.minor_id
= 0
45
46 --where d.name=‘要查询的表‘ --如果只查询指定表,加上此条件
47 ORDER BY a.id ,
48 a.colorder
结果:
数据库字典查询
标签: