Home > Database > Mysql Tutorial > body text

How to use mysql comment

(*-*)浩
Release: 2020-09-16 15:39:49
Original
16061 people have browsed it

In the MySQL database, comments on fields or columns are added using the attribute comment.

Recommended course: MySQL tutorial

How to use mysql comment

##In the script to create a new table,

You can add comments by adding the comment attribute in the field definition script.

The sample code is as follows:


create table test(
    id int not null default 0 comment '用户id'
)
Copy after login

If the table has already been built, You can also use the command to modify the fields, and then add the comment attribute Definition, you can add comments.
The sample code is as follows:

alter table test
change column id id int not null default 0 comment '测试表id'
Copy after login

How about viewing the comments of all fields in an existing table?

You can use the command: show full columns from tablename to view,

The example is as follows:

show full columns from test;
Copy after login
1. Write comments when creating the table

create table test1
(
    field_name int comment '字段的注释'
)comment='表的注释';
Copy after login
2. Modify table comments

alter table test1 comment '修改后的表的注释';
Copy after login
3. Modify field comments

alter table test1 modify column field_name int comment '修改后的字段注释';
--注意:字段名和字段类型照写就行
Copy after login
4. How to view table comments

--在生成的SQL语句中看
show  create  table  test1;
--在元数据的表里面看
use information_schema;
select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G
Copy after login
5. How to view field comments

--show
show  full  columns  from  test1;
--在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TAB
Copy after login

The above is the detailed content of How to use mysql comment. 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