Reputation: 1529
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.
Upvotes: 48
Views: 59727
Reputation: 16441
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 table";
Upvotes: 48
Reputation: 4993
Tested. this worked.
CREATE TABLE `table_with_comment` (
`id` int(11) NOT NULL,
`column_a` varchar(255) DEFAULT NULL COMMENT 'comment comlumn text',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='This is a table comment';
Upvotes: 1
Reputation: 2548
If you reached here looking for comments in DATABASE/SCHEMA, it's not supported in MySQL but it is in MariaDB:
https://mariadb.com/kb/en/create-database/
Upvotes: 0
Reputation: 810
Top voted answer worked for me only after equal sign removal. My working example would be
CREATE TABLE `example` (
`id` int(11) NOT NULL,
`two` varchar(255) COMMENT "comment text",
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Upvotes: 4
Reputation: 1532
if you want comment in table (in phpmyadmin) then follow these steps
Upvotes: 3
Reputation: 5107
This is an oldie, and there many response on how to update a columns comment, or create a table with comments. But the given answers on how to view the comments are rather awful
The easiest way to view the comments is via SHOW COLUMNS with the FULL keyword:
SHOW FULL COLUMNS FROM mytable
Upvotes: 8
Reputation: 5218
I just wrote an app for this.
Can be found here: https://github.com/SplicePHP/mysql-comments
Allows you to to update multiple database tables and columns in a single view.
Instructions in link.
Upvotes: -1
Reputation: 839
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.
Upvotes: 0
Reputation: 26762
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).
Upvotes: 0
Reputation: 109182
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'
Upvotes: 13
Reputation: 12486
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;
Upvotes: 43