C Sharper
C Sharper

Reputation: 8626

SQL : How to search column name in DB (within set of tables)

If my database has large set of tables then -

Is there any way / query which will search - which table contains particular column name ?

Eg. I want to know the name of table which contains column par_token.

How can I achieve this? - I am using SQL Management Studio 2014.

Upvotes: 0

Views: 72

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

I recommend using INFORMATION_SCHEMA.COLUMNS. The INFORMATION_SCHEMA views are (relatively) standard views available across databases. And, you don't need any joins:

select c.*
from information_schema.columns c
where c.column_name = 'par_token';

Upvotes: 1

Thom A
Thom A

Reputation: 95534

You can use the sys objects:

SELECT s.[name] AS SchemaName,
       t.[name] AS TableName
FROM sys.schemas s
     JOIN sys.tables t ON s.schema_id = t.schema_id
     JOIN sys.columns c ON t.object_id = c.object_id
WHERE c.[name] = N'par_token';

Upvotes: 2

Related Questions