码迷,mamicode.com
首页 > 其他好文 > 详细

查询表结构

时间:2014-12-09 17:12:50      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:des   io   ar   on   ad   ef   as   type   br   

select
obj.name as ‘表名‘
,c.name as ‘字段名称‘
,t.name as ‘字段类型‘
,c.Length as ‘占用字节‘
,COLUMNPROPERTY(c.id,c.name,‘PRECISION‘) as ‘长度‘
,isnull(COLUMNPROPERTY(c.id,c.name,‘Scale‘),0) as ‘小数位数‘
,case(c.isnullable) when ‘1‘ then ‘√‘ else ‘‘ end as ‘是否为空‘
,ISNULL(CM.text,‘‘) as ‘默认值‘
,case(
(select 1 from sysobjects where xtype=‘PK‘ and parent_obj=c.id and name in (
select name from sysindexes where indid in(
select indid from sysindexkeys where id = c.id and colid=c.colid)))
) when ‘1‘ then ‘√‘ else ‘‘ end as ‘是否主键‘
,case(COLUMNPROPERTY(c.id,c.name,‘IsIdentity‘)) when ‘1‘ then ‘√‘ else ‘‘ end as ‘自动增长‘

,isnull(ETP.value,‘‘) AS ‘字段描述‘

from syscolumns c
inner join systypes t on c.xusertype = t.xusertype
left join sys.extended_properties ETP on ETP.major_id = c.id and ETP.minor_id = c.colid and ETP.name =‘MS_Description‘
left join syscomments CM on c.cdefault=CM.id
left join sysobjects obj on c.id=obj.id
where c.id = object_id(‘表名称‘)

查询表结构

标签:des   io   ar   on   ad   ef   as   type   br   

原文地址:http://www.cnblogs.com/chengeng/p/4153398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!