- Blog - http://blog.bennett-scharf.com -
Searching for a column name in a SQL database
Posted By Bennett On 9. January 2008 @ 17:38 In T-SQL, SQL Server | No Comments
Here are a couple of different ways to search for a column name within a SQL Server database:
– using information_schema views (preferred method)
SELECT sc.table_name
FROM information_schema.columns sc
INNER JOIN information_schema.tables st
ON sc.table_name = st.table_name
WHERE st.table_type = ‘base table’
AND sc.column_name = ‘ColumnToFind’
ORDER BY sc.table_name
– old school
SELECT name
FROM sysobjects
WHERE id IN
(
SELECT id
FROM syscolumns
WHERE name = ‘ColumnToFind’ )
AND xtype = ‘U’
ORDER BY name
Article printed from Blog: http://blog.bennett-scharf.com
URL to article: http://blog.bennett-scharf.com/2008/01/09/searching-for-a-column-name-in-a-sql-database/
Click here to print.