I've been omitting the semicolon at the end of my MySQL queries recently, and it occurred to me that this might have possible negative effects maybe during server high load, caching etc. Are there any of such effects?
The semicolon (;) is used in SQL code as a statement terminator. For most SQL Server T-SQL statements it is not mandatory.
By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.
h , whitespace does not matter. They are interpreted as function calls only when used in expression context and may be used freely as identifiers otherwise.
It is not mandatory if you run a single query at time, it comes necessary instead if you want to run multiple query with a single command. As a rule of thumb, in JDBC semicolon is not necessary at all, if you need multiple statement use addBatch .
If the system is able to tell the end of the statement without the semicolon, omitting them does no harm. If the system gets confused, it matters. Since you've been able to leave them off, there isn't apparently a problem. A lot depends on how you're writing your SQL. If you're writing single statements in, say, PHP and then sending them to MySQL for processing, the semicolon is optional.
You ask if it "might have possible negative effects maybe during server high load, caching etc." The answer to that is 'No'. If it has an effect, it is on the basic interpretation of what you meant, and the difference is almost inevitably between 'it works' and 'it does not compile, let alone run'. Effects such as load or caching are completely independent of the presence or absence of semicolons.
This answer applies fairly generally. There's a reference to an SQL Server question which suggests that SQL Server did not need semicolons but is being changed in more recent editions so that they are necessary. It applies to most other DBMS. SQL command interpreters working on an SQL script need to know the boundaries between SQL statements, and the semicolon is the standard way of representing that, though there are other conventions (I believe some use go
and some use a slash /
for the job). But fundamentally, it comes down to "does it work". If it does, then the semicolon was not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With