In the mysql database, you can query the field types of the data table through the DESCRIBE statement; this statement can display the field information of the table in the form of a table, including the field name, field data type, whether it is the primary key, and whether There are default values, etc.; the syntax structure is "DESCRIBE table name", which can be abbreviated as "DESC table name".
(Recommended tutorial: mysql video tutorial)
DESCRIBE: In the form of a table Display table structure
DESCRIBE/DESC statement 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, and whether there is a default value etc.
The syntax format is as follows:
DESCRIBE <表名>;
or abbreviated as:
DESC <表名>;
[Example 1] Use DESCRIBE and DESC respectively to view the table structure and SQL statement of table tb_emp1 And the running results are as follows:
mysql> DESCRIBE tb_emp1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(25) | YES | | NULL | | | deptId | int(11) | YES | | NULL | | | salary | float | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 4 rows in set (0.14 sec) mysql> DESC tb_emp1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(25) | YES | | NULL | | | deptId | int(11) | YES | | NULL | | | salary | float | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 4 rows in set (0.14 sec)
The meaning of each field is as follows:
Null: Indicates whether the column can store NULL values.
Key: Indicates whether the column is indexed. PRI means that the column is part of the table's primary key, UNI means that the column is part of a UNIQUE index, and MUL means that a given value is allowed to occur multiple times in the column.
Default: Indicates whether the column has a default value, and if so, what is the value.
Extra: Indicates additional information related to a given column that can be obtained, such as AUTO_INCREMENT, etc.
The above is the detailed content of How to query the field types of mysql database table?. For more information, please follow other related articles on the PHP Chinese website!