views:

456

answers:

5

Hello everyone,

I often find myself spending a lot of time figuring out why certain SUM()-aggregates sum up wrongly in SQL-queries. This problem often occurs if I do not take care when adding a JOIN, resulting in duplicate values being summed up etc. If I work with a big query with lots of JOINs, nested subqueries, GROUP BYs etc. things get very complicated to debug.

I would like to know if there exist a tool that will make it easier to construct and debug complicated queries, by graphically illustrating the data being summed up, joined together etc.

An example of what I'm looking for is illustrated in http://www.imada.sdu.dk/~sorenh07/misc/datacentric-querytool.png

It is of course just an early mockup, and I am interested in any comment related to this.

+2  A: 

IMHO, the best "tool" for this is a textbook. This is one of those areas where the software can't do it for you. Sure, it can build simple selects & joins, but not aggregate functions or groupings, or sub-selects, etc. For that, you've got to learn to do it the old fashioned way -- by hand/wetware. I recommend: "Head First SQL" by Lynn Beighley, via O'Reilly Press

1) Get a book. 2) Install the database of your choice. 3) Import some test data. 4) Try to execute queries using as many functions as possible.

Practice, practice, practice.

lo_fye
I certainly agree with what you are saying... I have a lot of experience with SQL and databases in general - both the syntax and the theory behind - all of it learned the old fashioned way :-).What I would like is a piece of software to unveil the preliminary datasets from which a result is built, to make it easier to see where values gets wrongly duplicated, filtered etc. That is, I would like a tool which can give a *data centric* view of the query (showing the actual data used) and not purely *schema centric* (just showing which tables are in use etc.).
Søren Haagerup
I use Navicat to see the results of my queries. I have also used Eclipse's Database Explorer plugin.
lo_fye
+1  A: 

Every database comes with internal command to analyze complex sqls, explaining which join is not-efficient or taking more time to execute.

Ex: if you are using mysql then command is : explain

Niger
For Oracle you can use the comman "Explain plan"
Niger
+1  A: 

TOAD is probably the best multi-database tool for this sort of thing, however I do not believe there is any substitute for thoroughly groking SQL yourself. If you have difficulty constructing a query then it's going to be well nigh impossible to debug it effectively.

Cruachan
A: 

When my queries get too ugly, I find it helpful to use one of the many SQL beautifiers that are out there. These will not print graphics for you, but just proper indentation, syntax highlighting and brackets will help you out a good deal.

A: 

Check out the new Visual SQL Builder of MyEclipse 7.5.

zvikico