MySQL 如何找到包含 columnA 和 columnB 的所有表
要查找特定的列名,请使用 information_schema.columns。这里,我使用 Id 代替 columnA,使用 Name 代替 columnB −
mysql> select table_name as TableNameFromWebDatabase
-> from information_schema.columns
-> where column_name IN ('Id', 'Name')
-> group by table_name
-> having count(*) = 3;
这将产生以下输出。以下是具有 Id 和 Name 列的表 −
+--------------------------+
| TableNameFromWebDatabase |
+--------------------------+
| student |
| distinctdemo |
| secondtable |
| groupconcatenatedemo |
| indemo |
| ifnulldemo |
| demotable211 |
| demotable212 |
| demotable223 |
| demotable233 |
| demotable251 |
| demotable255 |
+--------------------------+
12 rows in set (0.25 sec)
为了证明,让我们检查其中一个表的描述。以下是查询 −
mysql> desc demotable233;
这将产生以下输出。在这里,您可以看到我们有 Int 和 Name 列 −
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| Id | int(11) | NO | PRI | NULL | auto_increment |
| Name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
阅读更多:MySQL 教程
极客教程