m-u
4/6/2016 - 10:43 AM

List all columns in tables and views

List all columns in tables and views

SELECT
          SO.NAME AS "Table Name"
        , SC.NAME AS "Column Name"
        , SM.TEXT AS "Default Value"
FROM
          dbo.sysobjects SO
          INNER JOIN
                    dbo.syscolumns SC
          ON
                    SO.id = SC.id
          LEFT JOIN
                    dbo.syscomments SM
          ON
                    SC.cdefault = SM.id
WHERE
          SO.xtype IN ('U'
                     ,'V')
ORDER BY
          SO.[name]
        , SC.colid