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

How to add comments to table in mysql

下次还敢
Release: 2024-04-22 19:54:12
Original
720 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

ALTER TABLE table_name COMMENT '备注文本';
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:

ALTER TABLE users COMMENT '用户信息';
Copy after login

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

CREATE TABLE table_name (
  ...
) COMMENT '备注文本';
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:

CREATE TABLE orders (
  ...
) COMMENT '订单信息';
Copy after login

Query Table Remarks

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

SELECT TABLE_COMMENT FROM information_schema.tables WHERE table_name = 'table_name';
Copy after login

For example, to query the comments of the

users table, you can use the following statement:

SELECT TABLE_COMMENT FROM information_schema.tables WHERE table_name = 'users';
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:
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template