Skip to content

Instantly share code, notes, and snippets.

@kristinaconley
Last active December 17, 2015 20:59
Show Gist options
  • Save kristinaconley/5671902 to your computer and use it in GitHub Desktop.
Save kristinaconley/5671902 to your computer and use it in GitHub Desktop.
/*SQL 2000 Find Column*/
SELECT
SO.NAME AS 'Table Name'
,SC.NAME AS 'Column Name'
,SM.TEXT AS 'Default Value'
FROM dbo.sysobjects SO (NOLOCK)
INNER JOIN dbo.syscolumns SC (NOLOCK) ON (SO.id = SC.id)
LEFT JOIN dbo.syscomments SM (NOLOCK) ON (SC.cdefault = SM.id)
WHERE
SO.xtype = 'U'
--AND sc.name LIKE '%program%' --Uncomment row if you would like to find a column name
ORDER BY SO.[name], SC.colid
/*SQL 2008 Find Column*/
SELECT
t.name AS 'Table Name'
,SCHEMA_NAME(t.schema_id) AS 'Schema'
,c.name AS 'Column Name'
,d.name AS 'Data Type'
,c.max_length
,C.precision
,c.scale
,c.is_nullable
FROM sys.tables t (NOLOCK)
INNER JOIN sys.columns c (NOLOCK) ON t.OBJECT_ID = c.OBJECT_ID
INNER JOIN sys.types d (NOLOCK) ON C.user_type_id = D.user_type_id
ORDER BY [Schema], [Table Name];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment