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

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

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

How to Determine if a Column Exists in a DataReader

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

Setting Default Values in an Angular Reactive Form