1

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.

Saswat
  • 11,464
  • 16
  • 68
  • 141

2 Answers2

1

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';
Ankit Agrawal
  • 2,377
  • 1
  • 12
  • 25
0

Try This Query

SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME ='Your Column Name' AND TABLE_SCHEMA='Your Database Name'
Divyesh
  • 369
  • 1
  • 12