Tuesday, May 17, 2016

SQL testbed sqlfiddle.com

First impression

I 'm so much impressed by this service www.sqlfiddle.com that I wanted to tell everybody about this. I discovered it through some questions and answers in stackoverflow, and I found out that it exists since 2012. I have seen several fiddles that enable online testing of other languages, but the magic of this one is that it's about databases, and you need to create and store your schema also. Moreover, you can choose among the main Database types and providers to test.

The problem(s)

I always wanted a test database server available and accessible from my PC to test different scenarios of tables, joins and performance of queries. I know it's nearly impossible to have installed Oracle, MySQL and MS SQL server on the same PC and test whatever you like... not to mention that some times the needs are to test on a specific version.

So, I was trying to find alternatives from buying a subscription to cloud services for all the above different DB vendors. Not to mention that I was thinking I could develop something like a test-bed and push it to the cloud... Fortunately, I recently found-out that somebody else did that.

Problem #1

You have a problem with a query for a client running Oracle. You are on the go and you don't have access to your development environment (of course) and you want to test the diagnostic query you want to send them before you send it (of course).

Problem #2

You have a brilliant idea on how to model your data and implement a special feature. But you don't have access to the development environment and even if you had, you don't want to bother with administration and installation of a DB server on your laptop. You just want to write SQL.

Problem #3

You want to help somebody in stackoverflow who is asking for help on a database-design SQL problem, or you may want to ask for help. The person who wants to ask for help can create a sample database schema and provide a query. That will be very convenient for other people wanting to help and reproduce the problem, as well as to test their suggested solution.

Solution

All you need is:
  1. to access www.sqlfiddle.com
  2. to select the corresponding DB server vendor and version. The supported databases list:
    • MySQL 5.6
    • MySQL 5.5
    • Oracle 11g R2
    • PostgreSQL 9.3
    • SQLite (WebSQL)
    • SQLite (SQL.js)
    • MS SQL Server 2014
    • MS SQL Server 2008
  3. to provide a schema creation script (or have it saved with a link)
  4. to provide a test data creation script (or have it saved with a link also) 

That's all. You are ready to test your diagnostic query before you send it.

More specifically:

Step 1: Select the corresponding Database and version.


Step 2: Provide the test schema creation script, and the sample data insert statements, on the left pane, and click on "Build Schema" button.

If the DB schema creation script has errors, then they will be reported at the bottom pane. If everything is fine, then the schema is created, and the right pane is activated where we can start testing our diagnostic queries.

Step 3: Ready to test your diagnostic query on the right pane. And the results appear on the bottom pane.

At the left pane, a schema browser is also available when clicking on the "Schema Browser" button. And as the results are presented in the bottom pane, a link for the "Execution Plan" is also available. What else to ask for?

Last but not least

You are thinking that sometimes you have to create a hundred of tables in order to replicate a database and address a special issue that you have. You are right, that's why www.sqlfiddle.com allows you to save your schema by keeping the link. And then you can access it from anywhere you have access to the Internet. For example, you can check the example I created for this post: http://www.sqlfiddle.com/#!9/5adfe.
The service also offers a free subscription option using authentication through Google+. This feature allows the user to maintain a list of schemas and queries under his account.

Credits

The project has been developed and maintained by Jake Feasel and it's open source at: https://github.com/jakefeasel/sqlfiddle2.



In the future

I wish this service keeps up to date with latest versions of RDBMS. Moreover, a nice to have feature would be if I could choose to provide Java code with JDBC on the right pane.

However, if you need to test your Java JDBC code on MySQL, then there is http://www.tutorialspoint.com/compile_jdbc_online.php for this purpose. A review of this service is coming soon.