2012-04-20

TSQL - Database objects and columns list


select
      -- Object
      o.name as [Object]
      , o.crdate as ObjectCreationDate
      , o.refdate as ObjectReferenceDate
     
      -- Column
      , c.colid as ColumnID
            , c.name as [Column]
      , c.colorder as ColumnOrder
      , c.type as ColumnTypeID
            , t.name as ColumnType
      , c.xusertype as ColumnUserType
      , c.length as ColumnLength
            , t.allownulls as ColumnAllowsNulls
      , c.collation as ColumnCollation
from
      -- Objects
      sysobjects o
     
      -- Columns
      inner join
      syscolumns c
      on
      o.id = c.id
     
      -- Column Types
      inner join
      systypes t
      on
      c.xtype = t.xtype
where
      -- Only tables, views, triggers and functions
      o.xtype in ( 'U', 'V', 'TR', 'TF' )
;

No comments:

Post a Comment