如何使用任何查询获取具有特定列名称的所有表名称?

时间:2021-01-17 08:00:27

Suppose I have 4 tables, named:-

假设我有4个表,名为: -

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

Now three tables have a field called users_id

现在三个表有一个名为users_id的字段

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

是否有查询可以告诉我所有具有列名称users_id的字段的表?

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

我甚至不知道是否可能。

2 个解决方案

#1


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';

#2


0  

Try This Query

试试这个查询

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

#1


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';

#2


0  

Try This Query

试试这个查询

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