取得  MySQL数据库表中的字段名的语句怎么写?

解决方案 »

  1.   

    desc tableName;mysql> DESCRIBE city;
    +------------+----------+------+-----+---------+----------------+
    | Field      | Type     | Null | Key | Default | Extra          |
    +------------+----------+------+-----+---------+----------------+
    | Id         | int(11)  | NO   | PRI | NULL    | auto_increment |
    | Name       | char(35) | NO   |     |         |                |
    | Country    | char(3)  | NO   | UNI |         |                |
    | District   | char(20) | YES  | MUL |         |                |
    | Population | int(11)  | NO   |     | 0       |                |
    +------------+----------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)
      

  2.   

    可以将字段名取出放到一个List表中吗?
      

  3.   

    use information_schema;
    select COLUMN_NAME from COLUMNS where TABLE_SCHEMA='your_database_name' and TABLE_NAME='tableName';