Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use comment in mysql

Shulou Source: shulou.com Published: 2022-06-01 03:30:07 10月07日 Update

Editor to share with you the use of comment in mysql, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

In the MySQL database, comments for fields or columns are added with the property comment.

In the script that creates the new table

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

The sample code is as follows:

Create table test (id int not null default 0 comment 'user id')

If it is a table that has already been built

You can also use the command to modify the field, and then add the comment attribute definition, you can add comments.

The sample code is as follows:

Alter table testchange column id id int not null default 0 comment 'test table id'

Check the comments for all the fields of the existing table?

You can view it with the command: show full columns from tablename

Examples are as follows:

Show full columns from test

1 write comments when creating the table

Create table test1 (comments for field_name int comment 'field') comments for the comment=' table'

2 modify the comments of the table

Alter table test1 comment 'comments on modified tables'

3 modify the comments of the field

Alter table test1 modify column field_name int comment 'modified field comments';-- Note: just write the field name and field type.

4 the method of viewing the comments of the table

-- look at show create table test1;-- in the generated SQL statement and look at use information_schema;select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'\ G in the metadata table.

5 ways to view field comments

-- showshow full columns from test1;-- look at select * from COLUMNS where TABLE_SCHEMA='my_db' and TAB in the metadata table. The above are all the contents of how to use comment in mysql. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Comments fields methods properties data examples usage code content commands articles scripts not so much available in most databases more users Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Docker Huawei Shulou Technology