Home  >  Article  >  Database  >  How to modify field comments in mysql

How to modify field comments in mysql

青灯夜游
青灯夜游Original
2021-12-01 17:29:2429924browse

In mysql, you can use the "ALTER TABLE" statement and the "column" keyword to modify field comments. The syntax is "alter table table name modify column field name field type comment 'modified field comment';" .

How to modify field comments in mysql

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

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

In the script that creates 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' 
)

If the table has been created, you can also use the command to modify the fields, and then add the comment attribute definition to add comments.

The sample code is as follows:

alter table test modify column id int not null default 0 comment '测试表id'

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

You can use the command: show full columns from table to view, the example is as follows:

show full columns from test;

Write comments when creating the table

create table test1 ( 
    field_name int comment '字段的注释' 
)comment='表的注释';

Modify the table Comment

alter table 表名 comment '修改后的表的注释';

Modify field comments

alter table 表名 modify column 字段名称 字段类型 comment '修改后的字段注释'; 

-- 注意:字段名和字段类型照写就行

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

How to view field comments

-- show 
	show  full  columns  from  test1; 
-- 在元数据的表里面看 
	select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G

[Related recommendations: mysql video tutorial

The above is the detailed content of How to modify field 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