从 MySQL 数据库中获取具有特定列(例如 xyz)的所有表?
mysqlmysqli database更新于 2025/12/25 10:20:17
假设我们有一个数据库"web",我们需要获取具有特定列"StudentFirstName"的所有表。
为此,以下是查询 −
mysql> select myColumnName.table_name from information_schema.columns myColumnName where myColumnName.column_name = 'StudentFirstName' and table_schema='web';
这将产生以下输出 −
+---------------+ | TABLE_NAME | +---------------+ | demotable109 | | demotable297 | | demotable335 | | demotable395 | | demotable418 | | demotable425 | | demotable436 | +---------------+ 7 rows in set (0.14 sec)
因此,上述表格中有一列名为"StudentFirstName"。
让我们检查任意表格的描述以查找列名"StudentFirstName" −
mysql> desc demotable297;
这将产生以下输出,显示其中一个列名为"StudentFirstName" −
+------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | StudentId | int(11) | YES | | NULL | | | StudentFirstName | varchar(100) | YES | | NULL | | | StudentLastName | varchar(100) | YES | | NULL | | +------------------+--------------+------+-----+---------+-------+ 3 rows in set (0.01 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

