Home >Database >Mysql Tutorial >How to add comments to table in mysql

How to add comments to table in mysql

下次还敢
下次还敢Original
2024-04-22 19:54:12649browse

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>

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>

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

<code class="sql">CREATE TABLE table_name (
  ...
) COMMENT '备注文本';</code>
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>

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>
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>

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!

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