首頁  >  文章  >  資料庫  >  如何在MySQL中尋找包含兩個特定列的所有表?

如何在MySQL中尋找包含兩個特定列的所有表?

WBOY
WBOY轉載
2023-09-07 22:29:02510瀏覽

如何在MySQL中尋找包含兩個特定列的所有表?

要尋找兩個特定的列名稱,請使用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中尋找包含兩個特定列的所有表?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除