1 SELECT
2 表名 =casewhen a.colorder=1then d.name else''end,
3 表说明 =casewhen a.colorder=1thenisnull(f.value,'') else''end,
4 字段序号 = a.colorder,
5 字段名 = a.name,
6 标识 =casewhenCOLUMNPROPERTY( a.id,a.name,'IsIdentity')=1then'√'else''end,
7 主键 =casewhenexists(SELECT1FROM sysobjects where xtype='PK'and parent_obj=a.id and name in (
8 SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then'√'else''end,
9 外键 =casewhenexists(SELECT1FROM sysforeignkeys WHERE sysforeignkeys.fkeyid = d.id and sysforeignkeys.fkey=a.colid) then'√'else''end,
10 类型 = b.name,
11 占用字节数 = a.length,
12 长度 =COLUMNPROPERTY(a.id,a.name,'PRECISION'),
13 小数位数 =isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
14 允许空 =casewhen a.isnullable=1then'√'else''end,
15 默认值 =isnull(e.text,''),
16 字段说明 =isnull(g.[value],'')
17 FROM
18 syscolumns a
19 leftjoin
20 systypes b
21 on
22 a.xusertype=b.xusertype
23 innerjoin
24 sysobjects d
25 on
26 a.id=d.id and d.xtype='U'and d.name<>'dtproperties'
27 leftjoin
28 syscomments e
29 on
30 a.cdefault=e.id
31 leftjoin
32 sys.extended_properties g
33 on
34 a.id=G.major_id and a.colid=g.minor_id
35 leftjoin
36
37 sys.extended_properties f
38 on
39 d.id=f.major_id and f.minor_id=0
40 where
41 d.name='SC'--这里为要查询的表名
42 orderby
43 a.id,a.colorder
1 --返回表名
2 select name from sysobjects where xtype='U'and id in
3 (
4 select id from syscolumns where name ='sno'--这里为外键字段名
5 and id in(select rkeyid from sysforeignkeys)
6 )