如何查詢有特定列名的所有表?


要編寫 MySQL 查詢以獲取所有有特定列名的表,我們可以使用 LIKE 運算子。透過以下示例可以理解 −

示例

下面是 MySQL 查詢,用於獲取所有其中包含列名“ID”的表 −

mysql> Select Column_name as 'ColumnName',Table_name As 'Tablename' FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%ID%' ORDER BY Tablename LIMIT 10;
+-------------+---------------+
| ColumnName  | Tablename     |
+-------------+---------------+
| id          | arena         |
| id          | arena1        |
| ID          | cars          |
| ID          | COLLATIONS    |
| ID          | copy_cars     |
| COUNTRY_ID  | countries     |
| REGION_ID   | countries     |
| Customer_Id | customers     |
| Customer_Id | customer_view |
| id          | emp           |
+-------------+---------------+
10 rows in set, 0 warnings (0.15 sec)

更新於: 2020-06-22

117 次瀏覽

啟動您的事業

完成課程以獲取認證

開始
廣告