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

为了编写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)