mysql sql文件注释,在相关的规范中,它记录在SQL脚本中的一些注释,事实上,作为有效的SQL(由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."

/*! 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值