SQL Server 2000
SQL Server 2005
1 SELECT
2 (case when a.colorder=1 then d.name else '' end)表名,
3 a.colorder 字段序号,
4 a.name 字段名,
5 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
6 (case when (SELECT count(*)
7 FROM sysobjects
8 WHERE (name in
9 (SELECT name
10 FROM sysindexes
11 WHERE (id = a.id) AND (indid in
12 (SELECT indid
13 FROM sysindexkeys
14 WHERE (id = a.id) AND (colid in
15 (SELECT olid
16 FROM yscolumns
17 WHERE (id = a.id) AND (name = a.name))))))) AND
18 (xtype = 'PK'))>0 then '√' else '' end) 主键,
19 b.name 类型,
20 a.length 占用字节数,
21 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
22 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
23 (case when a.isnullable=1 then '√'else '' end) 允许空,
24 isnull(e.text,'') 默认值,
25 isnull(g.[value],'') AS 字段说明
26
27FROM syscolumns a left join systypes b
28on a.xtype=b.xusertype
29inner join sysobjects d
30on a.id=d.id and d.xtype='U' and .name<>'dtproperties'
31left join syscomments e
32on a.cdefault=e.id
33left join sysproperties g
34on a.id=g.id AND a.colid = g.smallid
35order by a.id,a.colorder
2 (case when a.colorder=1 then d.name else '' end)表名,
3 a.colorder 字段序号,
4 a.name 字段名,
5 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
6 (case when (SELECT count(*)
7 FROM sysobjects
8 WHERE (name in
9 (SELECT name
10 FROM sysindexes
11 WHERE (id = a.id) AND (indid in
12 (SELECT indid
13 FROM sysindexkeys
14 WHERE (id = a.id) AND (colid in
15 (SELECT olid
16 FROM yscolumns
17 WHERE (id = a.id) AND (name = a.name))))))) AND
18 (xtype = 'PK'))>0 then '√' else '' end) 主键,
19 b.name 类型,
20 a.length 占用字节数,
21 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
22 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
23 (case when a.isnullable=1 then '√'else '' end) 允许空,
24 isnull(e.text,'') 默认值,
25 isnull(g.[value],'') AS 字段说明
26
27FROM syscolumns a left join systypes b
28on a.xtype=b.xusertype
29inner join sysobjects d
30on a.id=d.id and d.xtype='U' and .name<>'dtproperties'
31left join syscomments e
32on a.cdefault=e.id
33left join sysproperties g
34on a.id=g.id AND a.colid = g.smallid
35order by a.id,a.colorder
SQL Server 2005
1SELECT
2 (case when a.colorder=1 then d.name else '' end)表名,
3 a.colorder 字段序号,
4 a.name 字段名,
5 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
6 (case when (SELECT count(*)
7 FROM sysobjects
8 WHERE (name in
9 (SELECT name
10 FROM sysindexes
11 WHERE (id = a.id) AND (indid in
12 (SELECT indid
13 FROM sysindexkeys
14 WHERE (id = a.id) AND (colid in
15 (SELECT colid
16 FROM syscolumns
17 WHERE (id = a.id) AND (name = a.name))))))) AND
18 (xtype = 'PK'))>0 then '√' else '' end) 主键,
19 b.name 类型,
20 a.length 占用字节数,
21 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
22 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
23 (case when a.isnullable=1 then '√'else '' end) 允许空,
24 isnull(e.text,'') 默认值,
25 isnull(g.[value],'') AS 字段说明
26
27FROM syscolumns a left join systypes b
28on a.xtype=b.xusertype
29inner join sysobjects d
30on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
31left join syscomments e
32on a.cdefault=e.id
33left join sys.extended_properties g
34on a.id=g.major_id AND a.colid = g.major_id
35order by a.id,a.colorder
36
2 (case when a.colorder=1 then d.name else '' end)表名,
3 a.colorder 字段序号,
4 a.name 字段名,
5 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
6 (case when (SELECT count(*)
7 FROM sysobjects
8 WHERE (name in
9 (SELECT name
10 FROM sysindexes
11 WHERE (id = a.id) AND (indid in
12 (SELECT indid
13 FROM sysindexkeys
14 WHERE (id = a.id) AND (colid in
15 (SELECT colid
16 FROM syscolumns
17 WHERE (id = a.id) AND (name = a.name))))))) AND
18 (xtype = 'PK'))>0 then '√' else '' end) 主键,
19 b.name 类型,
20 a.length 占用字节数,
21 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
22 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
23 (case when a.isnullable=1 then '√'else '' end) 允许空,
24 isnull(e.text,'') 默认值,
25 isnull(g.[value],'') AS 字段说明
26
27FROM syscolumns a left join systypes b
28on a.xtype=b.xusertype
29inner join sysobjects d
30on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
31left join syscomments e
32on a.cdefault=e.id
33left join sys.extended_properties g
34on a.id=g.major_id AND a.colid = g.major_id
35order by a.id,a.colorder
36