Home >Database >Mysql Tutorial >How to query the number of fields in mysql
Query method: 1. Use the DESCRIBE statement to display the table structure, with the syntax "DESCRIBE table name;". The total number of record rows output is the number of fields; 2. Use the count() function to count the system table "information_schema. COLUMNS" to query the number of fields by specifying the number of data items.
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 display the field information of the table in the form of a 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 表名;
The total number of record rows output is the number of fields.
Example:
##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='表名';
##[Related recommendations: mysql video tutorial
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!