Find tables with specific column name in SQL Server database

Query below finds all tables that have 'ProductID' column.

See also tables that don't have a column with specific name.

Query

select schema_name(t.schema_id) as schema_name,
       t.name as table_name
from sys.tables t
where t.object_id in 
    (select c.object_id 
      from sys.columns c
     where c.name = 'ProductID')
order by schema_name,
         table_name;

Columns

  • schema_name - name of schema of found table
  • table_name - name of found table

Rows

  • One row represents a table
  • Scope of rows: all found tables
  • Ordered by schema name

Sample results

List of tables that have 'ProductID' column.

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.