Finding Tables in SQL Server That Contain a Certain Column Name

Here's a query you can run in SQL Server to find tables containing a certain column name -- just replace "UserId" in the WHERE clause below with the text of the column name you're searching for:

SELECT    t.name AS TableName,
        SCHEMA_NAME(schema_id) AS SchemaName,
        c.name AS ColumnName
FROM    sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE    c.name LIKE '%UserId%' -- Replace UserId with what you're looking for
ORDER BY SchemaName, TableName; 

Comments

Popular posts from this blog

How To Mock Out Child Components In Unit Tests of Angular 2 Code

A Generic Method Using HttpClient to Make a Synchronous Get Request

The Cause and Solution for the "System.Runtime.Serialization.InvalidDataContractException: Type 'System.Threading.Tasks.Task`1[YourTypeHere]' cannot be serialized." Exception