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
Post a Comment