Home > Database > Mysql Tutorial > body text

How to query the field types of mysql database table?

青灯夜游
Release: 2020-10-14 16:53:58
Original
8081 people have browsed it

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".

How to query the field types of mysql database table?

(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 <表名>;
Copy after login

or abbreviated as:

DESC <表名>;
Copy after login

[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)
Copy after login

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!

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 [email protected]
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!