Rachel
Rachel

Reputation: 103417

Given a column name how can I find which tables in database contain that column?

Note: Kindly explain answers with Examples as that I get most knowledge from the answer.

Edit: I am using MySQL Database.

Upvotes: 3

Views: 2750

Answers (3)

nickf
nickf

Reputation: 546035

SELECT * FROM information_schema.columns WHERE COLUMN_NAME = 'mycolumn'

Upvotes: 6

Manu
Manu

Reputation: 29143

in SQL Server:

select distinct t.name
from sys.Columns c 
    inner join sys.tables t on c.object_id = t.object_id
where c.name = 'YOUR_COLUMNNAME'

Upvotes: 0

mdm
mdm

Reputation: 12630

Depends on the database you are using. Many database systems expose a set of tables of views that contain details of the schema. For example, you can get schema information from the SYSTABLE and SYSCOLUMN views in Sybase ASA.

Upvotes: 0

Related Questions