在相关的规范中,它记录在SQL脚本中的一些注释,事实上,作为有效的SQL(由MySQL)执行? [英] Where in the relevant specification is it documented that some comments in a SQL script are, in fact, to be executed as valid SQL (by MySQL)?

查看:168
本文介绍了在相关的规范中,它记录在SQL脚本中的一些注释,事实上,作为有效的SQL(由MySQL)执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览由程序SQLYog为MySQL 5.6.16数据库生成的SQL转储时,我注意到每个存储过程 CREATE 语句被注释字符( / * * / )。



我很惊讶看到存储过程的注释 CREATE code>语句,然后看到这些注释语句实际上被执行。



看到这种情况发生了,我假设实际上是SQL标准,MySQL本身或SQLYog特定的文档,它支持执行至少一些注释的SQL代码。



这使我搜索规范文档布局有关在运行SQL脚本时执行某些已注释代码块的事实的详细信息。然而,一个整小时的搜索(特别是寻找官方规范,但二次搜索任何这样的文档,SQL,MySQL或SQLYog)只显示一个链接,甚至使引用事实上,在SQL脚本中注释的代码行,实际上,执行。这里是:链接到引用注释的SQL行执行(包括一些答案)。



我知道我很可能错过了这里明显的,

有人可以请确认,如果是的话,请提供参考,正式文件说明(并描述)SQL即使' / * * / '语法包含语句(无论这是SQL,MySQL还是SQLYog)?感谢。

解决方案

在手册中的注释语法下。



http://dev.mysql.com/doc/refman/ 5.6 / en / comments.html

  / *! MySQL特定代码* / 




在这种情况下,MySQL服务器解析和执行注释中的代码,因为它与任何其他SQL语句一样,但其他SQL服务器将忽略扩展。


...


在!字符之后添加一个版本号,只有当MySQL版本大于或等于指定的版本号时,才会执行注释中的语法。


在存储过程的情况下,整个声明被包装,所以如果你试图恢复在一个版本的MySQL服务器的旧版本的转储文件,它根本不支持存储过程,过程定义将被服务器忽略,而不是导致整个还原操作失败。


While browsing a SQL dump generated by the program SQLYog for a MySQL 5.6.16 database, I noticed that every stored procedure CREATE statement was surrounded by comment characters (/* */). However, the stored procedures were created when the SQL script was executed.

I was surprised both to see the comments surrounding the stored procedure CREATE statements, and then to see that these commented statements were, in fact, executed.

Seeing that this did occur, I assumed that in fact either the SQL standard, MySQL itself, or SQLYog specifically, documents that it supports the execution of at least some commented SQL code.

This caused me to search for the specification documentation laying out the details regarding the fact that some commented code blocks are executed when the SQL script is run. However, a full hour's search (looking, in particular, for the official specification, but secondarily searching for any such documentation for either SQL, MySQL, or SQLYog) has revealed literally only one link that even makes reference to the fact that commented lines of code in the SQL script are, in fact, executed. Here it is: link to reference that commented lines of SQL are executed (including some of the answers).

I'm aware that I am likely missing the obvious here, but I haven't been able to locate the specification for this.

Can someone please confirm, and if so please provide reference to, the formal documentation that states (and describes) the SQL that will be executed even if the '/* */' syntax surrounds the statement/s (whether this be SQL, MySQL, or SQLYog)? Thanks.

解决方案

It's in the manual, under "Comment Syntax."

http://dev.mysql.com/doc/refman/5.6/en/comments.html

/*! MySQL-specific code */ 

In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement, but other SQL servers will ignore the extensions. 

...

If you add a version number after the "!" character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number.

In the case of stored procedures, the entire declaration wrapped, so that if you tried to restore the dump file on a version of MySQL server that's so old it didn't support stored procedures at all, the procedure definitions would be ignored by the server instead of causing the entire restore operation to fail.

这篇关于在相关的规范中,它记录在SQL脚本中的一些注释,事实上,作为有效的SQL(由MySQL)执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆