Search Tables for Column Name

by Rick 12. August 2011 07:53
Depending on the level of convolutedness, one may, hopefully rarely, be required to search for all tables containing a particular column name.  I found myself in this situation today.  Refer to below T-SQL.
SELECT		so.name
FROM		sys.sysobjects AS so WITH(NOLOCK) INNER JOIN
			sys.syscolumns AS sc WITH(NOLOCK) ON so.id = sc.id
WHERE		(so.xtype = 'U') AND (sc.name = N'Column_Name')
ORDER BY	so.name

Tags:

SQL Server | T-SQL

blog comments powered by Disqus