SQL Server 101 – Search tables for a specific column name

You might want to search all the tables in your database for a specific column name in order to rename or perform some cleanup.

How to search tables for a specific column name in SQL Server ?

SELECT      columns.name  AS 'Column Name'
            ,tables.name AS 'TableName'
FROM        sys.columns AS columns
JOIN        sys.tables  AS tables   ON columns.object_id = tables.object_id
WHERE       columns.name LIKE '%Id%'
ORDER BY    TableName
            ,columns.name;

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this blog post, let’s learn about the error message “1459 – An error occurred while accessing the database mirroring...
In this blog post, let’s learn about the error message “7937 – Columnstore index has one or more missing column...