sELECT TableName= d.name,
TableExplain= isnull(f.value,''),
Clumnsnumber= a.colorder,
ClumnName= a.name,
ClumnExplain= isnull(g.[value],''),
ClumnIsIdentity= case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '自增标识' else '非自增' end,
ClumnIsIPrimary= 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,
ClumnType= b.name,
ClumnByte= a.length,
ClumnLen= COLUMNPROPERTY(a.id,a.name,'PRECISION'),
ClumnDeciam= isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
ClumnIsnull= case when a.isnullable=1 then '是' else '否' end,
ClumnDefault= isnull(e.text,'')
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 order by d.name