Find a column from all tables in a database on SQL Server

I recently have needed to find a column but could not remember what table it was in the database.

You can run this query on your SQL Server to find a specific column in the whole database:

SELECT COLUMN_NAME,  TABLE_NAME
FROM  INFORMATION_SCHEMA.COLUMNS
WHERE  COLUMN_NAME LIKE’ %ColumnName%’

You will need to replace the ColumnName(that is in red) with the actual name of your column that you are looking for. What this query actually does is query the Information Schema of the Database that holds all of the information about tables, views, columns and procedures to do with the database.

An example of this is say that you want to look for every table that has a ‘ClientCode’ column you can run the following query on the SQL database:

SELECT COLUMN_NAME,  TABLE_NAME
FROM  INFORMATION_SCHEMA.COLUMNS
WHERE  COLUMN_NAME LIKE’ %ClientCode%’

You might also like this video How to install SQL Server 2012 that takes you through the steps to install SQL Server.