http://www.netingcn.com/mysql-column-name.html

mysql安装成功后可以看到已经存在mysql、information_schema和test这个几个数据库,information_schema库中有一个名为COLUMNS的表,这个表中记录了数据库中所有表的字段信息。知道这个表后,获取任意表的字段就只需要一条select语句即可。例如:

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name';

上述的做法有一点问题,如果多个数据库中存在你想要查询的表名,那么查询的结果会包括全部的字段信息。通过DESC information_schema.COLUMNS可以看到该表中列名为TABLE_SCHEMA是记录数据库名,因此下面的写法更为严格

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name';

相关文章:

  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-01-01
  • 2021-06-10
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-12-24
  • 2021-12-20
  • 2022-02-04
  • 2021-05-23
相关资源
相似解决方案