SELECT
字段名=a.name,
类型=b.name,
字段说明=isnull(g.[value],''),
是否为空=case when a.isnullable=1 then 1 else 0 end,
是否自增=case when COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 then 1 else 0 end,
主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (
SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id=a.id AND colid=a.colid)))
then '√' else 'X' 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 in('U','V') 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='表名'
order by a.id,a.colorder