码迷,mamicode.com
首页 > 数据库 > 详细

查找SQL数据表或视图中的字段属性信息

时间:2015-04-22 18:01:03      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

一、只支持表,非常牛逼的

SELECT a.name,(case when (SELECT count(*) FROM sysobjects WHERE (name in (SELECT name FROM sysindexes WHERE (id = a.id) AND 
(indid in (SELECT indid FROM sysindexkeys WHERE (id = a.id) AND 
(colid in (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name))))))) AND (xtype = PK))>0 then 1 else 0 end) isprimary,
b.name [type],COLUMNPROPERTY(a.id,a.name,PRECISION) as [length],isnull(g.value,‘‘) as [description] 
FROM syscolumns a 
left join systypes b on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype=U and d.name<>dtproperties 
left join syscomments e on a.cdefault=e.id left join sys.extended_properties g on a.id=g.major_id AND a.colid = g.minor_id 
where  d.name =表明 
order by a.id,a.colorder

 

 

二,一般牛逼,支持表

select object_name(id) as 表名 ,c.name as 字段名 ,t.name 数据类型 ,c.prec as 长度 
from syscolumns c inner join systypes t on c.xusertype=t.xusertype 
where objectproperty(c.id,IsUserTable)=1 and c.id=object_id(表明)

 

三、一般牛逼,支持视图

select object_name(id) as 表名 ,c.name as 字段名 ,t.name 数据类型 ,c.prec as 长度  
from syscolumns c inner join systypes t on c.xusertype=t.xusertype 
where objectproperty(c.id,IsView)=1 and c.id=object_id(V_ALLSay) 

 

求大神非常牛逼的,既支持表也支持视图的sql

查找SQL数据表或视图中的字段属性信息

标签:

原文地址:http://www.cnblogs.com/fuyu-blog/p/4448018.html

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