如何查询有特定列名的所有表?
要编写 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)
广告