Home > Database > Mysql Tutorial > body text

mysql comment what does it mean

青灯夜游
Release: 2023-04-06 16:05:12
Original
7797 people have browsed it

comment means remarks and notes. In the MySQL database, comments on fields or columns are added using the comment attribute; in scripts that create new tables, comments can be added by adding the comment attribute in the field definition script. If you want to view the comments of all fields of an existing table, you can use the "show full columns from table name" command.

mysql comment what does it mean

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

In mysql, COMMENT means remarks and comments.

MySQL Add comment (comment)

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

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' 
)
Copy after login

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'
Copy after login

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;
Copy after login

Write comments when creating the table

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

Modify table comments

alter table test1 comment '修改后的表的注释';
Copy after login

Modify field comments

alter table test1 modify column field_name int comment '修改后的字段注释'; 

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

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

How to view field comments

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

Four kinds of comments in mysql

NO1:--Comment content

This comment method cannot implement multi-line comments. It should be noted that there is a space after --. (-- The following content will not be recognized, so you need to add a semicolon on the next line to end the statement)

mysql comment what does it mean

NO2 : #Comment content

This comment method cannot implement multi-line comments.

mysql comment what does it mean

NO3: /*Comment content*/

This kind of comment Ability to implement multi-line comments.

mysql comment what does it mean

Insert picture description here

NO4: /*!Comment content*/

This kind of comment is called inline comment in mysql, when! When the database version number is connected later, when the actual version is equal to or higher than that string, the application will interpret the comment content as SQL, otherwise it will be treated as a comment. By default, when the version number is not connected, the content inside will be executed.

mysql comment what does it mean

[Related recommendations: mysql video tutorial]

The above is the detailed content of mysql comment what does it mean. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!