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)?

耗尽温柔 提交于 2020-01-04 09:22:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25614919/where-in-the-relevant-specification-is-it-documented-that-some-comments-in-a-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!