Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create comments for views in mysql

I see that the views have a comment field just like the regular tables, but is by default populated with the "VIEW" value.

[TABLE_CATALOG] =>  [TABLE_SCHEMA] => xxx [TABLE_NAME] => view__xxxx [TABLE_TYPE] => VIEW [ENGINE] =>  [VERSION] =>  [ROW_FORMAT] =>  [TABLE_ROWS] =>  [AVG_ROW_LENGTH] =>  [DATA_LENGTH] =>  [MAX_DATA_LENGTH] =>  [INDEX_LENGTH] =>  [DATA_FREE] =>  [AUTO_INCREMENT] =>  [CREATE_TIME] =>  [UPDATE_TIME] =>  [CHECK_TIME] =>  [TABLE_COLLATION] =>  [CHECKSUM] =>  [CREATE_OPTIONS] =>  [TABLE_COMMENT] => VIEW 

When I am trying to create a view with a comment I get an error.

CREATE OR REPLACE VIEW view__x AS SELECT   *  FROM `some_table`   COMMENT = 'some comment' 

Is there a way to modify the comment field or that field is used internally for something else and should stay like it is?

I've added a feature request to mysql.

like image 603
Elzo Valugi Avatar asked Jan 17 '12 08:01

Elzo Valugi


People also ask

How do you add comments to a MySQL view?

MySQL Server supports three comment styles: From a # character to the end of the line. From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).

What is /* in MySQL?

This is a type of comment. The /* is the beginning of a comment and */ is the end of comment. MySQL will ignore the above comment.

Can we create views in MySQL?

By default, a new view is created in the default database. To create the view explicitly in a given database, use db_name. view_name syntax to qualify the view name with the database name: CREATE VIEW test.

How do I comment multiple lines in MySQL workbench?

Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored.


1 Answers

According to the create view syntax there is no way currently to add comment a view:

  • http://dev.mysql.com/doc/refman/5.7/en/create-view.html

This feature has been requested several times. There are four active tickets related to this functionality:

  • http://bugs.mysql.com/bug.php?id=5159
  • http://bugs.mysql.com/bug.php?id=64045
  • http://bugs.mysql.com/bug.php?id=52429
  • http://bugs.mysql.com/bug.php?id=15344

...and several marked as duplicates: http://bugs.mysql.com/bug.php?id=19602 , http://bugs.mysql.com/bug.php?id=19602 , http://bugs.mysql.com/bug.php?id=13109 , http://bugs.mysql.com/bug.php?id=14369 , http://bugs.mysql.com/bug.php?id=11082 , http://bugs.mysql.com/bug.php?id=42870 , http://bugs.mysql.com/bug.php?id=38137 , http://bugs.mysql.com/bug.php?id=38137 , http://bugs.mysql.com/bug.php?id=30729

If you are interested in this issue, go to the four active tickets, click the "affects me" button, and also add a comment, asking if anyone is working on this feature.

This will add visibility, and increase the likelyhood of it being implemented.

like image 94
Marjeta Avatar answered Oct 05 '22 02:10

Marjeta