Best tool for assisting writing complex SQL-queries? [closed]

五迷三道 提交于 2019-12-10 17:36:51

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


Check out the new Visual SQL Builder of MyEclipse 7.5.




回答6:


I use a visual tool called "Code Factory for MySQL". It's just for MySQL, but also a great learning tool.



来源:https://stackoverflow.com/questions/1284255/best-tool-for-assisting-writing-complex-sql-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!