Thursday, November 26, 2009

Find which tables contain a column name

Use the following query to get which tables contains EmployeeID as a column in a database.

SELECT t2.name [Table Name], t1.name [Column Name]
FROM syscolumns t1
INNER JOIN sysobjects t2 ON t1.id = t2.id
WHERE t1.name = 'EmployeeID'
AND t2.xtype = 'U'

No comments:

Post a Comment