在mysql中为视图创建注释

Elz*_*ugi 24 mysql comments views

我看到视图有一个注释字段,就像常规表一样,但默认情况下填充了"VIEW"值.

[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
Run Code Online (Sandbox Code Playgroud)

当我尝试使用注释创建视图时,我收到错误.

CREATE OR REPLACE VIEW view__x AS
SELECT 
 * 
FROM `some_table`  
COMMENT = 'some comment'
Run Code Online (Sandbox Code Playgroud)

有没有办法修改注释字段或该字段在内部用于其他东西,应该保持这样吗?

我已经向mysql 添加了一个功能请求.

Mar*_*eta 27

根据create view语法,目前无法添加注释视图:

已多次请求此功能.有四个与此功能相关的活动票证:

......和几个标记为重复:http://bugs.mysql.com/bug.php?id=19602,http://bugs.mysql.com/bug.php?id=19602,HTTP://错误.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

如果您对此问题感兴趣,请转到四个活动票证,单击"影响我"按钮,然后添加注释,询问是否有人正在使用此功能.

这将增加可见性,并增加其实施的可能性.

  • 哇!这 4 张门票仍然开放。其中之一是在 2004 年创建的! (2认同)

Jos*_*ber 5

我有类似的需求,我在 MySQL 中破解它的一种方法是在WHERE用作文档的子句中添加一个真谓词。我承认这是 hacky,但是您是否同意任何文档总比没有文档好?一旦以这种方式进行评论的良好副作用将在mysqldump. 据我所知,优化器不会受到额外的真实谓词的阻碍。

示例视图创建:

CREATE OR REPLACE VIEW high_value_employees AS
SELECT *
FROM `employees`
WHERE salary >= 200000
AND 'comment' != 'This view was made by Josh at the request of an important VP who wanted a concise list of who we might be overpaying. Last modified on 26 July 2019.';
Run Code Online (Sandbox Code Playgroud)

然后查看文档...

> SHOW CREATE TABLE high_value_employees \G
*************************** 1. row ***************************
                View: high_value_employees
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`jhuber`@`%` SQL SECURITY 
DEFINER VIEW `high_value_employees` AS select `employees`.`salary` AS `salary` from
`employees` where ((`employees`.`salary` >= 200000) and ('comment' <> 'This view was
made by Josh at the request of an important VP who wanted a concise list of who we
might be overpaying. Last modified on 26 July 2019.'))
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)