MySql视图脚本中的注释 [英] Comments in MySql view scripts
问题描述
是否可以这样做?我尝试了多个gui(mysql工作台,navicat,蟾蜍(适用于mysql)),但没有一个保存这样的注释:
-- something important
select .....
-- something else important
等
我正在经过一个设置吗?或者这是根本无法完成的事情?我问,因为TOAD for Oracle保存了我在上面的代码块中发布的内容.
mysql
命令行客户端将保存事件,功能,过程,触发器的注释,但前提是您包括--comments
选项.
通过创建具有以下内容的~/.my.cnf
文件,您始终可以拥有mysql
包含注释:
[mysql]
comments=1
不幸的是,即使提供了此选项,MySQL似乎也不会保留对VIEW的注释.
我决定将评论存储在VIEW中的唯一方法是在ORDER BY
字段的末尾包含一个虚拟字符串.例如:
CREATE
DEFINER = `root`@`localhost`
SQL SECURITY INVOKER
VIEW
ex
AS
SELECT
*
FROM
mysql.user
ORDER BY
user,
'a comment can go here';
访问 MySQL手册有关更多详细信息.
在MySQL 5.1之前,您可以在VIEW
内使用特定于MySQL的注释(/*! a comment */
),但是5.1和字母中的功能"已被删除.有关更多详细信息,请参见此处./p>
Is it possible to do so? I've tried multiple gui(mysql workbench, navicat, toad for mysql) and none of them save the comments like this:
-- something important
select .....
-- something else important
etc.
Is there a setting I am passing by or is this something that simply cannot be done? I ask since TOAD for Oracle saves what I posted in the code block above.
The mysql
command line client will save comments for EVENTs, FUNCTIONs, PROCEDUREs, TRIGGERs, but only if you include the --comments
option.
You can always have mysql
include comments, by creating a ~/.my.cnf
file with the following:
[mysql]
comments=1
Unfortunately, MySQL doesn't seem to preserve comments for VIEWs, even if this option is provided.
The only way I have determined to store comments inside a VIEW, is to include a dummy string at the end of the ORDER BY
fields. For example:
CREATE
DEFINER = `root`@`localhost`
SQL SECURITY INVOKER
VIEW
ex
AS
SELECT
*
FROM
mysql.user
ORDER BY
user,
'a comment can go here';
Visit the MySQL Manual for more details.
Before MySQL 5.1, you could use MySQL-specific comments (/*! a comment */
) inside VIEW
s, but that "feature" was removed in 5.1 and letter. See here for more details.
这篇关于MySql视图脚本中的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!