Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL and comments

Tags:

comments

mysql

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.

like image 652
Humpton Avatar asked Oct 14 '08 03:10

Humpton


People also ask

How do you comment out a statement in MySQL?

In MySQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.

How do I add comments to a table in MySQL?

The comments can be added to the MySQL columns while creating a table by adding the COMMENT keyword after the column definition, as shown above for column emp_name. The table is created successfully with comments. Confirm the same in column information using MySQL workbench.

How do I comment out a line in SQL Workbench?

i.e. The CONTROL + "/" using the division key above the keypad instead of the "?/" key on the main keyboard. It's not nearly as convenient, but it works for me with Windows 7 and MYSQL Workbench 6.1. Show activity on this post. Instead you can also simple type "#" at the Point of line you want to comment.

Which of the following is not valid comment in MySQL?

question. C option /*COMMENT is not a valid comment Line.


3 Answers

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;
like image 108
micahwittman Avatar answered Oct 12 '22 03:10

micahwittman


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";
like image 42
Gary Richardson Avatar answered Oct 12 '22 03:10

Gary Richardson


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'
like image 12
Robert Gamble Avatar answered Oct 12 '22 02:10

Robert Gamble