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

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

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

Silent Renew and the "login_required" Error When Using oidc-client

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

How to Determine if a Column Exists in a DataReader