Home > Database > Mysql Tutorial > How to view comments in mysql table

How to view comments in mysql table

藏色散人
Release: 2021-04-18 13:00:17
Original
6139 people have browsed it

How to view comments in mysql tables: 1. View the comments of all tables through the "information_schema.TABLES" statement; 2. Query the comments of all tables and fields through the "information_schema. TABLES a LEFT JOIN..." statement Notes etc.

How to view comments in mysql table

Recommended: "mysql video tutorial"

Mysql View table comments or field comments

View the comments of all tables

SELECT
table_name 表名,
table_comment 表说明
FROM
information_schema.TABLES
WHERE
table_schema = '数据库名'
ORDER BY
table_name
Copy after login

Query the comments of all tables and fields

SELECT
a.table_name 表名,
a.table_comment 表说明,
b.COLUMN_NAME 字段名,
b.column_comment 字段说明,
b.column_type 字段类型,
b.column_key 约束
FROM
information_schema. TABLES a
LEFT JOIN information_schema. COLUMNS b ON a.table_name = b.TABLE_NAME
WHERE
a.table_schema = '数据库名'
ORDER BY
a.table_name
Copy after login

Query the comments of all fields of a table

select 
COLUMN_NAME 字段名,
column_comment 字段说明,
column_type 字段类型,
column_key 约束 from information_schema.columns 
where table_schema = '数据库名'
and table_name = '表名' ;
Copy after login

or

show full columns from 表名;
Copy after login

View DDL generated by the table

Note that the table name does not include single quotes

show create table 表名;
Copy after login

Create a new table and add comments for tables and fields

create table t_user(
    ID INT(19) primary key auto_increment  comment '主键',
    NAME VARCHAR(300) comment '姓名',
    CREATE_TIME date comment '创建时间'
)comment  = '用户信息表';
Copy after login

Modify comments for tables/fields

Modify table comments

alter table t_user comment  = '修改后的表注释信息(用户信息表)';
Copy after login

Modify field comments

alter table t_user modify column id int comment '主键ID';
Copy after login

The above is the detailed content of How to view comments in mysql 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template