在数据库中的所有表中查找特定的列?
为此,请使用 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”的所有表。
广告