Home  >  Article  >  Database  >  How to add comments in mysql

How to add comments in mysql

青灯夜游
青灯夜游Original
2021-12-31 16:11:1215757browse

Mysql method to add comments: 1. Use the "alter table table name modify field name type constraint comment 'comment content';" statement to add comments to the field; 2. Use "alter table table name comment 'comment content' The ';' statement adds comments to the table.

How to add comments in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

How to add comments in MySql

**In the mysql database, comments on database tables and fields are added using the attribute comment. *

1. Add comments to fields:

#1) When creating a new table, add comments after the field constraints of the table.

For example:

create table users(id int(11) primary key comment ‘用户id’);

Here users is the table name, id is the field name, int (11) is the type, and primary key is the constraint.

2) If the table has been created, you can use the command to modify the fields and add the comment attribute.

For example:

alter table users modify name varchar(20)not null comment ‘用户名’;

Here users is the table name, name is the field name, varchar (20) is the type, and not null is the constraint.

2. Add comments to the table:

1) When creating a new table, write table comments outside the brackets.

For example:

create table users ( id int(11) primary key comment '用户id ') comment=‘用户信息表’;

2) After the table has been created, you can add comments when modifying the table.

For example:

alter table users comment ‘用户信息表’;

users here is the table name.

3. How to view table comments

show create table users;

Here users is the table name.

4. How to view field comments

show full columns from users;

Here users is the table name.

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to add comments in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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