In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to query the table structure of mysql". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to query the table structure of mysql.
Mysql query table structure method: 1, use the "DESCRIBE table name;" statement, will display the table structure in the form of a table; 2, use the "SHOW CREATE TABLE table name;" statement, will show the table structure in the form of SQL statement.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
After creating a data table, you often need to look at the table structure (table information). In MySQL, you can use the DESCRIBE and SHOW CREATE TABLE commands to view the structure of the data table.
DESCRIBE: show the table structure in tabular form
The DESCRIBE/DESC statement displays the field information of the table in the form of a table, including field name, field data type, whether it is a primary key, whether there is a default value, etc. The syntax format is as follows:
DESCRIBE table name
Or simply written as:
DESC table name
[example 1] use DESCRIBE and DESC to view the table structure of table tb_emp1, the SQL statement and the running result 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 meanings of each field are as follows:
Null: indicates whether the column can store NULL values.
Key: indicates whether the column is indexed. PRI indicates that the column is part of the table primary key, UNI indicates that the column is part of the UNIQUE index, and MUL indicates that multiple occurrences are allowed in a given value in the column.
Default: indicates whether the column has a default value, and if so, what the value is.
Extra: indicates additional information that can be obtained about a given column, such as AUTO_INCREMENT, and so on.
SHOW CREATE TABLE: show the table structure in the form of a SQL statement
The SHOW CREATE TABLE command displays the table information in the form of a SQL statement. Compared with DESCRIBE, SHOW CREATE TABLE shows more content, it can view the table storage engine and character encoding; in addition, you can also use\ g or\ G parameters to control the display format.
The syntax format of SHOW CREATE TABLE is as follows:
SHOW CREATE TABLE table name
Add the\ g or\ G parameter at the end of the SHOW CREATE TABLE statement (before the semicolon) to change the presentation.
[example 2] use the SHOW CREATE TABLE statement to view the details of the table tb_emp1, ending with\ g at one time and not using:
Mysql > SHOW CREATE TABLE tb_emp1 +-+-+ | Table | Create Table | +-+- -+ | tb_emp1 | CREATE TABLE `tb_ emp1` (`id` int (11) DEFAULT NULL `name` varchar (25) DEFAULT NULL, `salary` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=gb2312 | +-+-+ 1 row in set (0.01sec) mysql > SHOW CREATE TABLE tb_emp1\ g +-+-+ | Table | Create Table | +-+- -+ | tb_emp1 | CREATE TABLE `tb_ emp1` (`id` int (11) DEFAULT NULL `name` varchar (25) DEFAULT NULL, `salary` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=gb2312 | +-+-+ 1 row in set (0.00 sec)
SHOW CREATE TABLE uses the SQL statement that ends with\ G and the running result is as follows:
Mysql > SHOW CREATE TABLE tb_emp1\ Graph * 1. Row * * Table: tb_emp1Create Table: CREATE TABLE `tb_ emp1` (`id` int (11) DEFAULT NULL, `name` varchar (25) DEFAULT NULL, `deptId` int (11) DEFAULT NULL, `salary` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=gb23121 row in set (0.03 sec) I believe that you have a deeper understanding of "mysql how to query table structure", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.