Mar 14, 2008

SQLServer : Tables and Columns list

This SQL returns userr tables in current database and their columns.

SELECT
   O.name AS TableName
  ,C.name AS ColumnName
FROM
  sysobjects O
    INNER JOIN syscolumns C
    on 
      O.id = C.ID
WHERE
      OBJECTPROPERTY(O.id, N'IsUserTable') = 1 
  AND O.status >= 0   
ORDER BY
   O.name
  ,C.name

No comments: