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

查询字段的默认值

时间:2017-07-04 14:45:16      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:type   长度   pes   sql   数据类型   字段名   join   ext   获取   

--使用在SQL2008,***查询字段说明和默认值
select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
p.value as 字段说明   ,m.text as 默认值  
from syscolumns c   inner join   systypes t   on c.xusertype=t.xusertype   
left join  sys.extended_properties p   on c.id=p.major_id and c.colid = p.minor_id   
left join   syscomments m   on c.cdefault=m.id
-------------------------------------------------------------------------------------------
select * from sys.extended_properties  --SQL2008 扩展属性表(字段注释,)


----------------------------------------------------------------------------------------------------

/*在sql2000中使用*/

--获取所有默认值:

select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
inner join   systypes t   on c.xusertype=t.xusertype   
left join    sysproperties p   on c.id=p.id and c.colid = p.smallid   
left join   syscomments m   on c.cdefault=m.id

--获取单个字段默认值:

select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
inner join   systypes t   on c.xusertype=t.xusertype   
left join    sysproperties p   on c.id=p.id and c.colid = p.smallid   
left join   syscomments m   on c.cdefault=m.id  
where objectproperty(c.id,‘IsUserTable‘)=1   and object_name(c.id) = ‘表名‘ and c.name = ‘字段名称‘  




---------------------------------------------------------------------------------------------------
--查询指定表的指定字段的默认值
select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
inner join   systypes t   on c.xusertype=t.xusertype   
left join  sys.extended_properties p   on c.id=p.major_id and c.colid = p.minor_id    
left join   syscomments m   on c.cdefault=m.id  
where objectproperty(c.id,‘IsUserTable‘)=1   and object_name(c.id) = ‘表名‘ and c.name = ‘字段名‘  










 
 
 

  

查询字段的默认值

标签:type   长度   pes   sql   数据类型   字段名   join   ext   获取   

原文地址:http://www.cnblogs.com/accumulater/p/7116224.html

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