在数据库的所有表中查找特定列?
为此,请使用COLUMN_NAME并将LIKE设置为该特定的列名称。让我们在数据库的未知表中找到特定的列-
mysql> SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT -> FROM INFORMATION_SCHEMA.COLUMNS -> WHERE column_name LIKE '%StudentName%' -> AND table_schema = 'web';
输出结果
这将产生以下输出-
+-------------------+-------------+-----------+-------------+----------------+ | TABLE_NAME | COLUMN_NAME | DATA_TYPE | IS_NULLABLE |COLUMN_DEFAULT | +-------------------+-------------+-----------+-------------+----------------+ | demotable215 | StudentName | varchar | YES | NULL | | demotable221 | StudentName | varchar | YES | NULL | | demotable224 | StudentName | varchar | YES | NULL | | demotable234 | StudentName | varchar | YES | NULL | | demotable269 | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | NO | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | json | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | NO | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | DemoTable | StudentName | varchar | YES | NULL | | view_DemoTable | StudentName | varchar | YES | NULL | +-------------------+-------------+-----------+-------------+----------------+ 19 rows in set (0.07 sec)
上方显示所有带有特定列“StudentName”的表。