Query to Find Column Name From All Tables

Question : How many tables in your database have column name like  ‘CategoryID’  ?

Solution :

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE ‘%CategoryID%’
ORDER BY schema_name, table_name;

Question : How to find all the column name from your database ?

Solution :

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
ORDER BY schema_name, table_name;

Hope this will help

Jay Ganesh