Home  >  Article  >  Database  >  How to query the number of fields in mysql

How to query the number of fields in mysql

王林
王林forward
2023-04-17 18:49:064343browse

Query method: 1. Use the DESCRIBE statement to display the table structure, the syntax is "DESCRIBE table name;", the total number of record rows output is the number of fields; 2. By using the count() function Count the number of specified data items in the system table "information_schema.COLUMNS" to query the number of fields.

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

There are two ways to query the number of fields in a MySQL table

Method 1: Use the DESCRIBE statement

DESCRIBE will use the table's form to display the field information of the table, including field name, field data type, whether it is the primary key, whether there is a default value, etc. The syntax format is as follows:

DESCRIBE 表名;

can be abbreviated as:

DESC 表名;

Output The total number of record rows is the number of fields.

Example:

How to query the number of fields in mysql

##Method 2: Through the system table information_schema.`COLUMNS` (supported by mysql5 and above)

Query the number of fields by using the count() function to count the number of specified data items in the system table "information_schema.COLUMNS".

Syntax:


SELECT count(1) from information_schema.COLUMNS WHERE table_schema='库名' and table_name='表名';

  • table_schema: Database name

  • ##table_name: Table name
  • Example:


The above is the detailed content of How to query the number of fields in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete