In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is the method of querying the table structure under the database by mysql? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
Methods: 1, use DESCRIBE command to display table structure in the form of table, syntax "DESCRIBE table name;"; 2, use "SHOW CREATE TABLE" command to display table structure in the form of SQL statement, syntax "SHOW CREATE TABLE table name;".
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
Or simply written as:
DESC
[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
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\ gateway * 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) Thank you for your reading! After reading the above, do you have a general understanding of mysql's method of querying the structure of the table below the database? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
Note: this blog post is based on the table in the previous post, the previous post: MySQL basic query example (1). 1. Query all fname values corresponding to each s_id in the fruits table
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.