select
case when column_id=1 then a.name else '' end 表名,
case when column_id=1 then ISNULL(e.value,'') else '' end 表说明,
b.name 列名,
d.name 类型,
case when b.max_length=-1 then 'MAX' else cast(b.max_length as varchar(20)) end 类型长度,
isnull(c.value,'') 列说明,
case when i.name is not null then '√' else '' end 是否主键,
case when b.is_identity=1 then '√' else '' end 是否自增,
case when b.is_nullable=1 then '√' else '' end 是否可为空
from sys.tables a left join sys.columns b on a.object_id =b.object_id
left join sys.types d on b.user_type_id=d.user_type_id
left join sys.extended_properties c on b.object_id=c.major_id and c.minor_id=b.column_id
left join sys.extended_properties e on b.object_id=e.major_id and e.minor_id=0
left join (select * from (select * from sys.indexes where is_primary_key=1)g left join SYSINDEXKEYS h on g.object_id=h.id and g.index_id=h.indid)i on i.object_id=b.object_id and i.colid=b.column_id
order by a.name,b.column_id