Search for a column name in any table

Most directly, you can run this in SQL Server to confirm that a column exists — but that alone is only somewhat useful.

SELECT OBJECT_NAME(object_id) FROM sys.columns WHERE name = 'post_author';

Really what you want to know is both that the column exists and the table it lives in. So here’s a better alternative that joins sys.columns and sys.tables.

SELECT c.name  AS 'ColumnName', t.name AS 'TableName'
FROM sys.columns c
    JOIN sys.tables  t ON c.object_id = t.object_id
WHERE   c.name LIKE '%post_author%'
ORDER BY TableName, ColumnName;
Default image
Eric
Code guy.

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply