SELECT SO.Name as ItemName, SC.Name as ColumnName, ST.Name as ColumnType,
CASE WHEN ST.Status = 2 THEN '(' + CONVERT(VarChar(6), SC.Length) + ')' ELSE CASE WHEN SC.AutoVal IS NOT NULL THEN 'IDENTITY' END END As ColumnTypeExtras,
CASE WHEN Left(SysIndexLookup.IndexType, 2) = 'PK' THEN 'PRIMARY KEY' ELSE '' END as KeyText, SCom.Text as Contents, SO.XType, 'DEFAULT ' + SD.Text AS DefaultValue, SCom.ColID
FROM SysObjects SO LEFT OUTER JOIN SysColumns SC ON
SO.ID = SC.ID LEFT OUTER JOIN SysTypes ST ON
SC.XType = ST.XType LEFT OUTER JOIN
(SELECT SI.ID, SI.Name as IndexType, SIK.ColID
FROM SysIndexes SI INNER JOIN SysIndexKeys SIK ON
SI.ID = SIK.ID AND
SI.IndID = SIK.IndID) SysIndexLookup ON
SO.ID = SysIndexLookup.ID AND SC.ColID = SysIndexLookup.ColID LEFT OUTER JOIN SysComments SCom ON
SO.ID = SCom.ID LEFT OUTER JOIN
(SELECT sysobjects.id, sysobjects.name, sysobjects.parent_obj, syscomments.text
FROM SysObjects INNER JOIN SysComments ON
SysObjects.id = SysComments.id AND SysObjects.xType = 'D') SD ON
SC.CDefault = SD.ID
WHERE SO.XType NOT IN ('S','PK','F','D') AND
Left(SO.Name, 2) NOT LIKE 'dt%'
ORDER BY SO.ID