Home > Database > Mysql Tutorial > body text

How to add comments to table in mysql

下次还敢
Release: 2024-04-22 19:54:12
Original
609 people have browsed it

MySQL tables can add comments through the ALTER TABLE or CREATE TABLE statement to provide purpose information about the table and its columns. To query table comments, use the SELECT TABLE_COMMENT FROM information_schema.tables WHERE table_name = 'table_name' statement.

How to add comments to table in mysql

How to add comments to a MySQL table

Adding comments to a MySQL table helps provide information about the table and its columns purpose information. This is important for other developers, database administrators, and end users to understand the table structure and data.

There are two ways to add comments to a MySQL table:

1. Use the ALTER TABLE statement

<code class="sql">ALTER TABLE table_name COMMENT '备注文本';</code>
Copy after login

For example, to add a comment named ## To add the comment "User Information" to the #users table, you can use the following statement:

<code class="sql">ALTER TABLE users COMMENT '用户信息';</code>
Copy after login

2. Use the CREATE TABLE statement (only applicable to creating new tables)

<code class="sql">CREATE TABLE table_name (
  ...
) COMMENT '备注文本';</code>
Copy after login
For example, to create a new table named

orders and add a comment as "Order Information", you can use the following statement:

<code class="sql">CREATE TABLE orders (
  ...
) COMMENT '订单信息';</code>
Copy after login

Query Table Remarks

To query the comments of the table, you can use the following statement:

<code class="sql">SELECT TABLE_COMMENT FROM information_schema.tables WHERE table_name = 'table_name';</code>
Copy after login
For example, to query the comments of the

users table, you can use the following statement:

<code class="sql">SELECT TABLE_COMMENT FROM information_schema.tables WHERE table_name = 'users';</code>
Copy after login

The above is the detailed content of How to add comments to table in mysql. 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!