Saswat
Saswat

Reputation: 12806

How to get all the tables' name having specific column name using any query?

Suppose I have 4 tables, named:-

  1. tbl_user
  2. tbl_doctor
  3. tbl_chat_request
  4. tbl_payment

Now three tables have a field called users_id

Is there are query which can tell me all the tables which has a field with column name users_id?

I don't even have any idea if it is possible or not.

Upvotes: 1

Views: 37

Answers (2)

Divyesh
Divyesh

Reputation: 389

Try This Query

SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME ='Your Column Name' AND TABLE_SCHEMA='Your Database Name'

Upvotes: 0

Ankit Agrawal
Ankit Agrawal

Reputation: 2454

Get table name from schema like below

SELECT DISTINCT TABLE_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME ='users_id'
AND TABLE_SCHEMA='db_name';

Upvotes: 1

Related Questions