Getting the name of the table in which a column with specified name appears

- less than 1 minute read

Sometimes you need to find out in which tables a certain column name exists. For example when you want to find out where it’s being used as a foreign key. Here’s a handy script to use in T-SQL.

SELECT OBJECT_NAME(/images/object_id), * FROM sys.columns WHERE name = 'columnname'

This makes use of the OBJECT_NAME function in T-SQL which according to the documentation: Returns the database object name for schema-scoped objects.

Grz, Kris.

Tags:

Updated: -

Leave a Comment