MSSQL sql脚本生成数据字典(表结构文档)的方法

    [是否标识别]=case when is_identity=1 then '是' else '' end,
    [是否主鍵]=case when exists(select 1 from sys.objects x join sys.indexes y on x.Type=N'PK' and x.Name=y.Name 
                        join sysindexkeys z on z.ID=a.Object_id and x.parent_object_id = and z.indid=y.index_id and z.Colid=a.Column_id)
                    then '是' else '' end,
    [列长度]=case when ColumnProperty(a.object_id,a.Name,'Precision')=-1 then '2^31-1'
                else rtrim(ColumnProperty(a.object_id,a.Name,'Precision')) end,
    [可null标志]=case when a.is_nullable=1 then '√' else '' end,
    sys.columns a(nolocK)
left join
    sys.types b(nolocK) on a.user_type_id=b.user_type_id
inner join
    sys.objects c(nolocK) on a.object_id=c.object_id and c.Type='U'
left join
    syscomments d(nolocK) on a.default_object_id=d.ID
left join
    sys.extended_properties e(nolocK) on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1 
left join
    sys.extended_properties f(nolocK) on f.major_id=c.object_id and f.minor_id=0 and f.class=1