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

How to query the number of fields in mysql

青灯夜游
青灯夜游Original
2022-04-12 16:17:369983browse

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.

How to query the number of fields in mysql

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:

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:


##[Related recommendations: How to query the number of fields in mysqlmysql 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!

Statement:
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