In ms SQL Server 2000, find the System ID, name, and comment information of all user tables and user views in a database:
Select
( Case When A. colorder = 1 Then D. Name Else '' End ) Table Name,
A. Serial number of the colorder field,
A. Name field name,
( Case When Columnproperty (A. ID, A. Name, ' Isidentity ' ) = 1 Then ' √ ' Else '' End ) ID,
( Case When ( Select Count ( * )
From Sysobjects
Where (Name In ( Select Name
From Sysindexes
Where (ID = A. ID) And
(Indid In ( Select Indid
From Sysindexkeys
Where (ID = A. ID) And
(Colid In ( Select Colid
From Syscolumns
Where (ID = A. ID) And (Name = A. Name)
)
)
)
)
)
) And (Xtype = ' PK ' )) > 0 Then ' √ ' Else '' End ) Primary key,
B. Name type,
A. Length occupies the number of bytes,
Columnproperty (A. ID, A. Name, ' Precision ' ) As Length,
Isnull ( Columnproperty (A. ID, A. Name, ' Scale ' ), 0 ) As Decimal places,
( Case When A. isnullable = 1 Then ' √ ' Else '' End ) Can be empty,
Isnull (E. Text , '' ) Default value,
Isnull (G. [ Value ] , '' ) As Field description
From Syscolumns Left Join Policypes B
On A. xtype = 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 Sysproperties g
On A. ID = G. ID And A. colid = G. smallid
Order By A. ID, A. colorder