March 2, 2016

Find column in database

This script finds all tables with a specific column in the database:

SELECT t.name AS table_name,
SCHEMA_NAME(schema_idAS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c 
ON t.OBJECT_ID c.OBJECT_ID
WHERE c.name LIKE '%ClientID%'
ORDER BY schema_nametable_name;