首页 > 代码库 > 获取某个表的字段,字段类型等属性

获取某个表的字段,字段类型等属性

SELECT  
  --字段序号
  fieldNo = a.colorder,
  -- 字段名 
  fieldName = a.name,
  --类型
  fieldType = b.name,
  --长度
  fieldLength = COLUMNPROPERTY(a.id,a.name,PRECISION),
  --小数位数
  pointDigits = isnull(COLUMNPROPERTY(a.id,a.name,Scale),0),
  -- 允许空
  allowEmpty = case when a.isnullable=1 then else  end,
  --字段说明
  fieldDescript = isnull(g.[value],‘‘)
  
FROM  
  syscolumns a
left join  
  systypes b  
on  
  a.xusertype=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   
left join 
sys.extended_properties f
on  
  d.id=f.major_id and f.minor_id=0
where  
--表名!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!需要修改!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  d.name=pur_receipt_line 
order by  
  a.id,a.colorder 

 

获取某个表的字段,字段类型等属性