1. 程式人生 > >查詢字段的默認值

查詢字段的默認值

columns rop obj 註釋 scom 擴展屬性 default 名稱 字段說明

--使用在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 = ‘字段名‘  










 
 
 

  

查詢字段的默認值