sql server 表结构 导出 到excel
1 SELECT 2 表名 = case when a.colorder=1 then d.name else '' end, 3 表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end, 4 -- 字段序号 = a.colorder, 5 字段名 = a.name, 6 标识 = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end, 7 主键 = case when exists(SELECT 1 FROM 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 类型 = b.name, 10 占用字节数 = a.length, 11 长度 = COLUMNPROPERTY(a.id,a.name,'PRECISION'), 12 小数位数 = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0), 13 允许空 = case when a.isnullable=1 then '√'else '' end, 14 默认值 = isnull(e.text,''), 15 字段说明 = isnull(g.[value],'') 16 FROM 17 syscolumns a 18 left join 19 systypes b 20 on 21 a.xusertype=b.xusertype 22 inner join 23 sysobjects d 24 on 25 a.id=d.id and d.xtype='U' and d.name<>'dtproperties' 26 left join 27 syscomments e 28 on 29 a.cdefault=e.id 30 left join 31 sys.extended_properties g 32 on 33 a.id=G.major_id and a.colid=g.minor_id 34 left join 35 36 sys.extended_properties f 37 on 38 d.id=f.major_id and f.minor_id=0 39 -- where d.name='C_PARTY_SPREADER' --如果只查询指定表,加上此条件 40 order by 41 a.id,a.colorder
转自 http://blog.csdn.net/shandian534/article/details/39249245