Reputation: 12806
Suppose I have 4 tables, named:-
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
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
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