Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do Oracle and MySQL add comments to the table

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how Oracle and MySQL add comments to tables". In daily operation, I believe many people have doubts about how Oracle and MySQL add comments to tables. Xiaobian consulted all kinds of data and sorted out simple and easy to use operation methods. I hope to help you answer the doubts of "how Oracle and MySQL add comments to tables"! Next, please follow the small series to learn together!

In MySQL and Oracle databases, comments on fields or columns are added using the attribute comment. In scripts that create new tables, you can add comments by adding the comment attribute to the field definition script. Here is how to add comments. If you need them, please refer to them.

Oracle Add Comment

In Oracle databases, field or column comments are added with attribute comments.

1. Add comments to the table:

comment on table table name is 'comment content of table';

The example code is as follows:

comment on table user is 'user table';

2. Add comments to the fields of the table:

comment on column name. field name is 'field comment';

The example code is as follows:

comment on column user.username is 'user name field in user table';

MySQL Add comment

In MySQL databases, field or column comments are also added with attribute comments.

1. In scripts that create new tables, you can add comments by adding the comment attribute to the field definition script.

The example code is as follows:

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

2. 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 example code is as follows:

alter table test change column id int not null default 0 comment 'test table id'

View comments for all fields of an existing table?

You can view it with the command: show full columns from table, for example:

show full columns from test;

Write comments when creating tables

create table test1 ( field_name int comment 'field comment' )comment='table comment';

Modify comments for tables

alter table test1 comment 'comment on the modified table';

Modify comments for fields

alter table test1 modify column field_name int comment 'field comment after modification';--Note: field name and field type can be copied

How to view table comments

--See in generated SQL statements show create table test1; --Look inside the metadata table 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; --View in table of metadata select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G At this point, the study of "how Oracle and MySQL add comments to tables" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report