tags:

views:

323

answers:

5
+4  Q: 

MySQL and comments

Is it possible to add comments somehow, somewhere?

I don't pretend to be any sort of expert when using MySQL and certainly don't spend all day in it. More often than I would like I forget how I intend to use a column (usally the bit ones) and would be very excited if I could add a comment to remind me if 1 is good or bad, for example.

I'd be happy if it only showed up in something like 'show create table', but any obscure place within the table structures would be better and easier to find than the current post-it notes on my desk.

+1  A: 

Are you sure you're not looking to use an ENUM column instead? Good MySQL tables should be self-documenting.

An alternate approach would be to comment the schema files that have the SQL you use to define your tables (I assume you have those, and that you're not using PHPMyAdmin to grow table schemas on the fly...)

But if you insist, the INFORMATION_SCHEMA COLUMNS table, specifically the COLUMN_COMMENT column, is probably what you're looking for. It's proprietary MySQL syntax though, so I would tend to avoid it (although the idea of database interoperability is really a joke).

Edward Z. Yang
You know, I might be. But, my low-level of expertise has not translated into much success with the whole ENUM thing. I do like to have 'good' tables so I'll think about ENUMs some more sometime soon.
Humpton
+5  A: 

http://dev.mysql.com/doc/refman/5.0/en/create-table.html

table_option:
    {ENGINE|TYPE} [=] engine_name
  | AUTO_INCREMENT [=] value
  | AVG_ROW_LENGTH [=] value
  | [DEFAULT] CHARACTER SET [=] charset_name
  | CHECKSUM [=] {0 | 1}
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'string'


Example:

CREATE TABLE foo (
  id int(10) NOT NULL auto_increment COMMENT 'unique ID for each foo entry',
  bar varchar(255) default NULL COMMENT 'the bar of the foo',
  ....
) TYPE=MyISAM;
micahwittman
+2  A: 

MySQL supports comments on tables and columns which will show up on show create:

create table example (field1 char(3) comment 'first field') comment='example table'
Robert Gamble
A: 

You can comment columns and tables:

CREATE TABLE example (
  example_column INT COMMENT="This is an example column",
  another_column VARCHAR COMMENT="One more column"
) TYPE=MYISAM COMMENT="This is a comment about tables";
Gary Richardson
A: 

If you use the MySQL Administrator tool to manage/edit your databases, whenever you use the Table Editor, the comment for each column is automatically shown/editable.

Stringent Software
I don't. I'm a low skill level command line creator * PHP enter / change / extract data type user.
Humpton