简体   繁体   中英

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.

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';

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM