Home > Database > Mysql Tutorial > body text

How to query the field name of the table in mysql

WBOY
Release: 2022-04-12 18:43:14
Original
10766 people have browsed it

The "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'database name' AND TABLE_NAME = 'table name'" statement can be used in mysql to query the field name of the table.

How to query the field name of the table in mysql

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

How to query the field name of the table in mysql

Use the following statement to query:

select COLUMN_NAME from information_schema.COLUMNS 
where table_name = ‘your_table_name’;
Copy after login

There is a problem with the above approach. If the field name you want to query exists in multiple databases table name, then the query results will include all field information.

In MySQL, you can use the SELECT statement to query data. Querying data refers to using different query methods to obtain different data from the database according to needs. It is the most frequently used and important operation.

information_schema, which stores all database information (such as table names, column names, corresponding permissions, etc.),

You can see through DESC information_schema.COLUMNS that the column name in the table is TABLE_SCHEMA Record the database name, so the following writing is more strict

Add database name

SELECT COLUMN_NAME FROM information_schema.COLUMNS 
WHERE TABLE_SCHEMA = '数据库名称' AND TABLE_NAME = '表名称';
Copy after login

The results displayed in the visualization tool MySQL Workbench are similar to the following:

How to query the field name of the table in mysql

Recommended learning: mysql video tutorial

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

Related labels:
source:php.cn
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!