Search for Column Name in All Tables

In MS SQL Server 2000 and above there is an undocumented stored procedure that enables you to search through all tables for a particular column name. Example usage:

SQL:
  1. sp_MSforeachdb
  2. 'print ''?'';
  3. use [?];
  4. select table_name
  5. from information_schema.columns
  6. where column_name like ''TheColumnNameToFind'''

Note: select the "Results in Text" or "Results to Text" option before executing the above.

Thanks to my friend Ras for this tip.

22 April 2008 | MS SQL | Comments

Comments:

  1.  
  2.  
  3.