Skip to content

Instantly share code, notes, and snippets.

@umair-me
Created April 6, 2016 10:43
Show Gist options
  • Save umair-me/bdba575e49350ae2bfe8f1577ef61365 to your computer and use it in GitHub Desktop.
Save umair-me/bdba575e49350ae2bfe8f1577ef61365 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment