create table (...)comment='table_comment';
您可以通过以下方式显示注释:
show table status where name='table_name';
创建表注释后如何更改(更改?)表注释。我的意思是放下并重新创建表。
#1 楼
DROP TABLE IF EXISTS test_comments;
Query OK, 0 rows affected (0.08 sec)
CREATE TABLE test_comments (ID INT, name CHAR(30)) COMMENT 'Hello World';
Query OK, 0 rows affected (0.22 sec)
检查表结构中的注释
show create table test_comments\G
*************************** 1. row ***************************
Table: test_comments
Create Table: CREATE TABLE `test_comments` (
`ID` int(11) DEFAULT NULL,
`name` char(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Hello World'
1 row in set (0.00 sec)
还可以从information_schema中检查注释,如下所示
SELECT TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_NAME = 'test_comments';
+---------------+
| TABLE_COMMENT |
+---------------+
| Hello World |
+---------------+
1 row in set (0.00 sec)
更改注释的修改表
ALTER TABLE test_comments COMMENT = 'This is just to test how to alter comments';
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
检查已修改的注释
show create table test_comments\G
*************************** 1. row ***************************
Table: test_comments
Create Table: CREATE TABLE `test_comments` (
`ID` int(11) DEFAULT NULL,
`name` char(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='This is just to test how to alter comments'
1 row in set (0.00 sec)
SELECT TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_NAME = 'test_comments';
+--------------------------------------------+
| TABLE_COMMENT |
+--------------------------------------------+
| This is just to test how to alter comments |
+--------------------------------------------+
1 row in set (0.00 sec)
评论
谢谢你的详细解释,alter table修改评论正是我在找
– v14t
2014-02-25 10:22
额外的问题:直接从information_schema.columns修改column_comment是否安全(因为alter table ...再次要求指定所有列定义)?
– e2-e4
17年11月6日在8:37
@ e2-e4,information_schema表实际上是只读视图。您不能直接修改它们。但是好问题!
–pbarney
20年8月7日13:00