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