Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to find all tables in a database that have a column with a specific name

What query can I run on a database that will tell me which tables in that database have a column named "RCPTNMBR"?

like image 204
Scott Avatar asked Jan 14 '11 01:01

Scott


2 Answers

Most databases support this:

SELECT 
    table_name 
FROM 
    information_schema.columns 
WHERE
    column_name = 'x'
like image 105
Ken Downs Avatar answered Sep 22 '22 04:09

Ken Downs


Give this a try

SELECT t.name as TableName, c.name as ColumnName
FROM sys.tables t
JOIN sys.columns c ON t.object_id = c.object_id
WHERE c.name = 'RCPTNMBR'
like image 26
bobs Avatar answered Sep 25 '22 04:09

bobs