Check MySQL syntax

v_decadence's profile image v_decadence posted 8 years ago in Feature discussion Permalink
Hello.
Is there any way to check query syntax on Query tab before executing?
Or can I execute query to check if it's right but without actually applying changes to database?
ansgar's profile image ansgar posted 8 years ago Permalink
You could fire a "EXPLAIN <your query>" Query to check it. If it has a Syntax error, MySQL will tell you so. If not, MySQL just returns some analysis rows.
v_decadence's profile image v_decadence posted 8 years ago Permalink
Hi, ansgar. Thanks for the answer, but I have many statements, run EXPLAIN for each is very long way.
Moreover, "Before MySQL 5.6.3, SELECT is the only explainable statement." so it can't explain other statements types on earlier versions of MySQL.
I wish to check all in .sql file and run it after succesful check.
v_decadence's profile image v_decadence posted 8 years ago Permalink
So what's about it?
ansgar's profile image ansgar posted 8 years ago Permalink
You can perhaps wrap your whole SQL code in a transaction and cancel that in the end, like this:
BEGIN TRANSACTION;
INSERT INTO...;
DELETE FROM...;
ROLLBACK TRANSACTION;
v_decadence's profile image v_decadence posted 8 years ago Permalink
It's option, but don't you plan create native function for this need?
ansgar's profile image ansgar posted 8 years ago Permalink
No, definitely not. The MySQL server is the only instance which can check the SQL syntax reliably.

Please login to leave a reply, or register at first.