Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test SQL for validity from the command line?

Is there a good tool for ensuring that an SQL query is valid ANSI SQL, and optionally what DBMSs will fail to interpret it? I've found http://developer.mimer.com/validator but I was wondering whether there is a command line tool, preferably open source.

like image 256
Kim Stebel Avatar asked Dec 30 '08 10:12

Kim Stebel


People also ask

How do I check if a SQL query is correct?

Check - The check is a way for you to check if you have written a legal SQL query. Arrow - This is the execute command button. This will send the query to the server and the server will write back the result to you. Square - This is the stop execution command.


2 Answers

Here is a SQL Library that can help you to do vendor-specific offline SQL syntax check via command line, both Java and .NET demo were available.

like image 105
James Wang Avatar answered Oct 04 '22 03:10

James Wang


Maybe a parser/generator like ANTLR or JavaCC has an ANSI SQL 92 grammar already built. If so, you can run the parser/generator, build the classes that come out, and Bob's your uncle.

I see that ANTLR has one that's based on Oracle PL/SQL. Maybe that can help you. ANTLR is a terrific tool, well worth knowing.

like image 36
duffymo Avatar answered Oct 04 '22 03:10

duffymo