mysql获取某个表的全部字段名

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

    上述的作法有一点问题,若是多个数据库中存在你想要查询的表名,那么查询的结果会包括所有的字段信息。经过DESC information_schema.COLUMNS能够看到该表中列名为TABLE_SCHEMA是记录数据库名,所以下面的写法更为严格sql

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' 
and table_schema = 'your_db_name';
相关文章
相关标签/搜索