Info

You are currently browsing the Blog weblog archives for the day 9. January 2008.

Calendar
January 2008
S M T W T F S
« Dec   Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031  
Categories

Archive for 9. January 2008

Searching for a column name in a SQL database

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

|