Skip to main content

Find the Table Name

Ever came across a situation where you know a column name but don't remember the table name. This is the third incident that i forgot the table name and so thought of penning it down.

How I Solved It?
I will just share the queries that will help you get this done. I am sure that would be more than enough.

Query 1:
                             SELECT  *
                             FROM    sys.columns
                             WHERE   name LIKE   '%column_name%'

This query will give you list of object_id and names that has the column name in it Using the object id we can find the object.

Query 2:

                             SELECT  *
                             FROM    sys.objects
                             WHERE   object_id IN  (..., ... , obejct ids from query 1..., ...)


This query will give you the object name and type.  The object of type U are user tables. These tables are list of tables that have the column that we we were looking for

Comments