select
表的名称 = case when a.colorder=1 then d.name else '' end,
表的说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,
字段序号 = a.colorder,
字段名称 = a.name,
字段说明 = isnull(g.[value],''),
字段类型 = case when b.name='decimal' or b.name='numeric'
then b.name + '(' + CONVERT(varchar(10), a.prec) + ',' + CONVERT(varchar(10), a.xscale) +')'
when b.name like '%char'
then b.name + '(' + (case when a.length=-1 then 'max' else CONVERT(varchar(10), iif(b.name LIKE 'n%',a.length/2,a.length)) end) + ')'
else b.name end,
字段长度 = a.length,
小数位数 = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
允许为空 = case when a.isnullable=1 then '√'else '' end,
为默认值 = isnull(e.text,''),
为自增列 = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
是否主键 = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
select name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then '√' else '' end
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 1=1
--and d.name='SalesOrder'
-- and d.name='PnCustomer'
and d.name='ProductNumber';
03-08
1783
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-14
3111
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)