Home > Database > Mysql Tutorial > body text

How to query the number of fields in mysql

王林
Release: 2023-04-17 18:49:06
forward
4342 people have browsed it

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 表名;
Copy after login

can be abbreviated as:

DESC 表名;
Copy after login

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='表名';
Copy after login
  • 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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!