SELECT o.name as TableName,
USER_NAME(o.uid) as OWNER,
ISNULL(ptb.value,N' ') as TableDescription,
c.colid as FieldId,
c.name as FieldName,
QUOTENAME(t.name)
+CASE
WHEN t.name IN (N'decimal ',N'numeric ')
THEN N'( '+CAST(c.prec as varchar)+N', '+CAST(c.scale as varchar)+N') '
WHEN t.name=N'float '
OR t.name like N'%char '
OR t.name like N'%binary '
THEN N'( '+CAST(c.prec as varchar)+N') '
ELSE N' ' END
+CASE WHEN c.isnullable=1 THEN N' ' ELSE N' NOT ' END+N' NULL ' as FieldType,
ISNULL(pfd.value, ' ' ) as FieldDescription,
c.length as DefileLength,
ISNULL(df.text,N' ') as FieldDefault,
case COLUMNPROPERTY(o.id,c.name,N'IsIdentity ') when 1 then '√' else '' end as IsIDENTITY,
case COLUMNPROPERTY(o.id,c.name,N'IsComputed ') when 1 then '√' else '' end as IsComputed,
case COLUMNPROPERTY(o.id,c.name,N'IsRowGuidCol ') when 1 then '√' else '' end as IsROWGUID,
CASE WHEN opk.xtype IS NULL THEN '' ELSE '√' END as IsPrimaryKey
FROM sysobjects o
JOIN syscolumns c
ON c.id=o.id
AND OBJECTPROPERTY(o.id,N'IsUserTable ')=1
JOIN systypes t
ON t.xusertype=c.xusertype
LEFT JOIN syscomments df
ON df.id=c.cdefault
LEFT JOIN sysproperties ptb
ON ptb.id=o.id and ptb.smallid=0
LEFT JOIN sysproperties pfd
ON pfd.id=o.id and pfd.smallid=c.colid
LEFT JOIN sysindexkeys idxk
ON idxk.id=o.id
AND idxk.colid=c.colid
LEFT JOIN sysindexes idx
ON idx.indid=idxk.indid
AND idx.id=idxk.id
AND idx.indid NOT IN(0,255)
LEFT JOIN sysobjects opk
ON opk.parent_obj=o.id
AND opk.name=idx.name
AND OBJECTPROPERTY(opk.id,N'IsPrimaryKey ')=1
ORDER BY o.name,c.colid