68

Is there any site available online for verifying the syntax which conforms to multiple databases?

For example: If I have a SQL statement with a 'usage' keyword, then the site should throw me an error saying that 'usage' keyword is reserved in MYSQL?

Phani
  • 5,319
  • 6
  • 35
  • 43
  • Similar question: http://stackoverflow.com/questions/7753081/are-there-any-sql-validators-that-can-check-syntax-against-multiple-database-ser – Randall Cook Dec 14 '12 at 07:53

6 Answers6

21

You could try a formatter like this

They will always be limited because they don't (and can't) know what user defined functions you may have defined in your database (or which built-in functions you have or don't have access to).

You could also look at ANTLR (but that would be an offline solution)

Gary Myers
  • 34,963
  • 3
  • 49
  • 74
  • Gary, It could be any user defined function, what I mean is in any where in SQL script, if it finds a keyword of any database type, it should raise an error is what I'm expecting for. – Phani Feb 17 '11 at 10:00
  • 2
    @Phani: It's difficult to even say what's a reserved keyword. Here's the official list of [Oracle reserved keywords](http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10830/appb.htm#BABGHAFH) for 11gR2, but testing shows that some of them aren't truly reserved. For example, `notfound`, `arraylen`, `sqlbuf`, `rowlabel` shouldn't work as a column name but they do. A 100% solution is almost certainly impossible. You may want to add some more details about what you're doing and how much accuracy you need. – Jon Heller Feb 24 '11 at 00:15
  • I'm a Java Developer in process of building a frame work, so, due to less expertise, I added a SQL statement to repository, which bulbed the framework. So, from next time onwards, I want to feed that input to any online site to verify does it contain any reserved words.I hope, I answered your question. – Phani Feb 24 '11 at 05:55
7

Have you tried http://www.dpriver.com/pp/sqlformat.htm?

Infotekka
  • 10,307
  • 2
  • 20
  • 17
  • Tried, but it's only identifying SQL Syntax issues, but not the reserved keywords/functions. – Phani Mar 02 '11 at 07:35
5

I haven't ever seen such a thing, but there is this dev tool that includes a syntax checker for oracle, mysql, db2, and sql server... http://www.sqlparser.com/index.php

However this seems to be just the library. You'd need to build an app to leverage the parser to do what you want. And the Enterprise edition that includes all of the databases would cost you $450... ouch!

EDIT: And, after saying that - it looks like someone might already have done what you want using that library: http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl

The online tool doesn't automatically check against each DB though, you need to run each manually. Nor can I say how good it is at checking the syntax. That you'd need to investigate yourself.

Michael Broughton
  • 4,045
  • 14
  • 12
4

Only know about this. Not sure how well does it against MySQL http://developer.mimer.se/validator/

RemoteSojourner
  • 733
  • 5
  • 6
  • The link is purely based on SQL standard, irrespective of standards database organisations(MySQL,Oracle etc) tend to use different keywords because of limitations. It's a good start but not what I'm looking for. Thanks for the reply. – Phani Feb 16 '11 at 11:37
3

I don't know of any such, and my experience is that it doesn't currently exist. Most are side by side comparisons of two databases. That information requires experts in all the databases encountered, which isn't common. Versions depend too, to know what is supported.

ANSI functions are making strides to ensure syntax is supported across databases, but it's dependent on vendors implementing the spec. And to date, they aren't implementing the entire ANSI spec at a time.

But you can crowd source on sites like this one by asking specific questions and including the databases involved and the versions used.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
2

I am willing to bet some of my reputation that there is no such thing.

Partially because if you are worried about cross-platform SQL compatibility, your best bet in turn is to abstract your database code with some API or ORM tool that handles these things for you, and is well supported, so will deal with newer database versions as they come out.

Exact kind of API available to you will be dependent on your programming language/platform. For example, PHP has Pear:DB and others, I personally have found quite nice Python's ORM features implemented in Django framework. I presume there should be some of these things available on other platforms as well.

Gnudiff
  • 4,297
  • 1
  • 24
  • 25