How do you search for table field names in MySQL?

There are two methods available to query the field names of a MySQL table:

  1. DESC command: By using the DESC command, one can obtain the structure information of a table, including field names, data types, key types, and more. To execute this command in a MySQL command prompt or client, use the following syntax:
DESC 表名;

For example:

DESC employees;

This will retrieve the field information of the employees table.

  1. You can retrieve the field names of a table by querying the tables information in the INFORMATION_SCHEMA database. Execute the following SQL statement:
SELECT column_name 
FROM information_schema.columns 
WHERE table_schema = '数据库名' 
AND table_name = '表名';

Replace “database name” with the actual name of the database, and “table name” with the actual name of the table. For example:

SELECT column_name 
FROM information_schema.columns 
WHERE table_schema = 'mydatabase' 
AND table_name = 'employees';

This will return the field names of the employees table.

You can obtain the field names of a MySQL table using any method.

bannerAds