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:
##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='表名';
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!