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.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Use the following statement to query:
select COLUMN_NAME from information_schema.COLUMNS where table_name = ‘your_table_name’;
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 = '表名称';
The results displayed in the visualization tool MySQL Workbench are similar to the following:
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!