当前位置:网站首页>Five ways to query MySQL field comments!
Five ways to query MySQL field comments!
2022-07-05 01:28:00 【Brother Lei talks about programming】
A lot of scenarios , We need to check MySQL Notes to middle table , Or the notes of all fields under a table , So this article will count and compare several ways of querying comments .
Create test database
Before we start, let's create a database , For the following demonstration .
-- If it exists, delete the database first
drop database if exists test2022;
-- Create database
create database test2022;
-- Switch database
use test2022;
-- Create tables and fields ( And corresponding notes )
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT ' Student number ',
`sn` varchar(50) DEFAULT NULL COMMENT ' Student number ',
`username` varchar(250) NOT NULL COMMENT ' Student name ',
`mail` varchar(250) DEFAULT NULL COMMENT ' mailbox ',
`class_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) comment=' Student list ' ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
Query all table comments
Use the following SQL You can query the comments of all tables under a database :
SELECT table_name Table name , table_comment Table description
FROM information_schema.TABLES
WHERE table_schema=' Database name '
ORDER BY table_name
- 1.
- 2.
- 3.
- 4.
Case study : Inquire about test2022 All table annotations in the database :
SELECT table_name Table name , table_comment Table description
FROM information_schema.TABLES
WHERE table_schema='test2022'
ORDER BY table_name
- 1.
- 2.
- 3.
- 4.
The execution result is shown in the figure below :

Query all field comments
Field annotation query method 1
The query syntax is as follows :
show full columns from Table name ;
- 1.
Case study : Inquire about student Comment information for all fields in the table :
show full columns from student;
- 1.
The execution result is shown in the figure below :

Field annotation query method 2
The query syntax is as follows :
select COLUMN_NAME Field name ,column_comment Field description ,column_type Field type ,
column_key constraint from information_schema.columns
where table_schema=' Database name ' and table_name=' Table name ';
- 1.
- 2.
- 3.
Case study : Inquire about student Comment information for all fields in the table :
select COLUMN_NAME Field name ,column_comment Field description ,column_type Field type ,
column_key constraint from information_schema.columns
where table_schema='test2022' and table_name='student';
- 1.
- 2.
- 3.
The execution result is shown in the figure below :

Field annotation query method 3
Query table DDL( Data definition language ) You can also see the comment content of the field , Executive SQL The grammar is as follows :
show create table Table name ;
- 1.
Case study : Inquire about student Comment information for all fields in the table :
show create table student;
- 1.
The execution result is shown in the figure below :

Field annotation query method 4
If you are using Navicat Tools , You can right-click on the table 、 More design , You can view the field comments on the design page , As shown in the figure below :

But this kind of operation is a little dangerous , Be careful to shake your hands and correct the structure of the watch .
Field annotation query method 5
stay Navicat View the table in DDL Statement can also see the field comments , Select the table and click the lower right foot “ Show the right window ” Options , Then click DDL You can show , The specific operation steps are shown in the figure below :

Modify table comments and field comments
Modify table notes
Modify the syntax of table comments :
alter table Table name comment =' Modified table comments ';
- 1.
Case study : modify student Table comments for :
alter table student comment =' Student list V2';
- 1.
The execution result is shown in the figure below :

Modify field comments
Modify the syntax of table comments :
alter table Table name modify column Field name int comment ' Annotation information ';
- 1.
Case study : modify student In the table name Notes :
alter table student modify column username int comment ' The student's name V2';
- 1.
The execution result is shown in the figure below :

summary
This article introduces how to view table comments SQL, And modify the notes of tables and fields SQL, It also introduces how to view field comments 5 Methods :3 A command line operation mode to view , Two methods based on Navicat How to operate view , Which is recommended SQL:“show full columns from Table name ” View field comments , This kind of inquiry SQL Simple and don't worry about changing the table structure by mistake .
It's up to you to judge right and wrong , Disdain is to listen to people , Gain or loss is more important than number .
official account :Java Analysis of the real interview questions
Follow the QR code below , Subscribe to more .

author : Wang lei's blog
边栏推荐
- 【大型电商项目开发】性能压测-优化-中间件对性能的影响-40
- Introduction to the gtid mode of MySQL master-slave replication
- Classification of performance tests (learning summary)
- Chia Tai International Futures: what is the master account and how to open it?
- Database performance optimization tool
- Inventory of more than 17 typical security incidents in January 2022
- 小程序直播 + 电商,想做新零售电商就用它吧!
- Talking about JVM 4: class loading mechanism
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- Global and Chinese market of portable CNC cutting machines 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Database performance optimization tool
![Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)](/img/ad/5fbf8c3f71ea204bcd48473c3811f6.png)
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)

Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature

微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益

Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!

A simple SSO unified login design

Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)

【海浪建模2】三维海浪建模以及海浪发电机建模matlab仿真

Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
![[flutter topic] 64 illustration basic textfield text input box (I) # yyds dry goods inventory #](/img/1c/deaf20d46e172af4d5e11c28c254cf.jpg)
[flutter topic] 64 illustration basic textfield text input box (I) # yyds dry goods inventory #
随机推荐
Robley's global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Blue Bridge Cup Square filling (DFS backtracking)
Arbitrum:二维费用
Chia Tai International Futures: what is the master account and how to open it?
Four pits in reentrantlock!
Database postragesq BSD authentication
Basic operation of database and table ----- phased test II
Heartless sword English translation of Xi Murong's youth without complaint
Package What is the function of JSON file? What do the inside ^ angle brackets and ~ tilde mean?
batchnorm.py这个文件单GPU运行报错解决
JS implementation determines whether the point is within the polygon range
After reading the average code written by Microsoft God, I realized that I was still too young
Compare whether two lists are equal
[development of large e-commerce projects] performance pressure test - Optimization - impact of middleware on performance -40
如果消费互联网比喻成「湖泊」的话,产业互联网则是广阔的「海洋」
Global and Chinese markets for industrial X-ray testing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
流批一体在京东的探索与实践
Global and Chinese market of optical densitometers 2022-2028: Research Report on technology, participants, trends, market size and share
Detailed explanation of multi-mode input event distribution mechanism
LeetCode周赛 + AcWing周赛(T4/T3)分析对比