Strangenut

How to find all tables with a column of a particular name in SQL Server 2005 and 2008

This is a simple query for finding all instances of a column with a particular name along with the table that it belongs to.  This will not work on SQL Server 2000.

select sys.objects.name as TableName, sys.columns.name as ColumnName 
  from sys.columns
 inner join sys.objects on sys.objects.object_id = sys.columns.object_id 
 where sys.columns.name = 'countyid'


Posted Feb 13 2009, 01:37 AM by dacrowlah
Powered by Community Server (Non-Commercial Edition), by Telligent Systems