コメントを含めてテーブルを作成する
mysql> create table test( -> message varchar(200) comment 'カラムのコメント' -> ) -> engine=MyISAM -> default charset=utf8 -> comment='テーブルのコメント'; Query OK, 0 rows affected (10.91 sec)
- カラムのコメントは「comment '入れたいコメント'」という形式
- テーブルのコメントは「comment='入れたいコメント'」という形式
書き方が微妙に違うので紛らわしい。
コメントの確認
mysql> select column_name, column_comment from information_schema.columns where table_name='test'; +-------------+--------------------------+ | column_name | column_comment | +-------------+--------------------------+ | message | カラムのコメント | +-------------+--------------------------+ 1 row in set (7.75 sec)
mysql> select table_name, table_comment from information_schema.tables where table_name='test'; +------------+-----------------------------+ | table_name | table_comment | +------------+-----------------------------+ | test | テーブルのコメント | +------------+-----------------------------+ 1 row in set (4.32 sec)
コメントの変更
mysql> alter table test modify message varchar(200) comment 'カラムのコメント(修正)'; Query OK, 0 rows affected (7.67 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table test comment 'テーブルのコメント(修正)'; Query OK, 0 rows affected (5.61 sec) Records: 0 Duplicates: 0 Warnings: 0