I have just searched through StackOverflow but couldn't find much... To all the SQL experts, is there anything comparable to the "design patterns movement" which has taken place in the programming language world since 1994? You know, the "Gang of Four" book and the like. I'm asking because I feel the need to structure/organize typical SQL constructs for educational purposes. The question is focussing primarily on querying, not on data modeling. These possible patterns might classify
and the like. Such rules of thumb may be something like
(I don't claim this is a valid solution, it's just the way I would like a sample to be.) And I expect them to be general approaches though the possible solutions will obvioulsy depend on the features of the SQL engine - i.e. are WINDOW functions available). In that respect, I would prefer solutions working with SA 11.0.1 and above:) Any hints are highly appreciated! [Just do clarify: Inspite of the heavy usage of "like" and "pattern" in this question, I am not at all refering to pattern matching:)] |
In a word, the answer is "yes" though I think many references merely scratch the surface. As one example, a relatively new book by Vadim Tropashko offers solutions to the following patterns:
but as useful as these patterns may be, to me these are merely a part of the problem. In my view, "Design Patterns" with relational databases must include both logical and physical schema design since there are always tradeoffs between the SQL constructions one might use and aspects of the physical schema that render the queries (or updates) possible (or not), and what their performance characteristics may be. 1
Some more information and reviews: http://www.amazon.com/SQL-Design-Patterns-Programming-Focus/dp/0977671542/ref=sr_1_1?ie=UTF8&s=books&qid=1265457511&sr=1-1 Replies hidden
Comment Text Removed
Thanks for the pointer - I'm gonna have a look at that, as the book seems to be available here, too:) 1
@Glenn: I agree with your point of view that designing queries can't be separated from the schema design. - But sometimes you have to work with an already fixed schema (of a 3rd party vendor's application), And that's what I am dealing with currently:) Dang! After over a year, you would think they would have some used copies in the $20 range. No chance. This must be a great book. You're still paying over $50 for a used one. :) Jeff Gibson
(13 May '11, 16:50)
Jeff Gibson
|
No personal offense intended, but I'm tempted to create the tag "architecture-astronaut"... :)
Seriously, why don't you post some individual questions, like "When should a correlated subquery be used instead of a join, and vice versa?"
Um... try googling "sql design patterns"
Dear Breck, I appreciate your comment, but I am really interested whether users of this fine website have any hints to helpful books on these topics, or what iAnywhere experts have to say. It's definetely not an individual question I have but the general question if there is some valuable collection of such questions/answers. - And I try to keep grounded:)
Just to add: There seem to be some collections of particular problems when using certain types of queries in Oracle, MS SQL and the like, cf. the site **http://explainextended.com. I don't know if there is something comparable focussed on SA (besides the NGs and this site). As stated, it's more for educational purposes*, not to find a way how to formulate one particular query. For the latter, I would (and will!) ask that particular question here.
FWIW I have a fairly large number of what I call "templates"... snippets of SQL in text files arranged by meaningful file and folder names, which I use all the time in my own work (and often copy and paste into forum answers). I imagine that some other folks might have the same thing, a personal "toolkit". I have often thought about publishing them, but that would be a large effort... much cleanup would be required, and the only true motivators (fear and greed) are missing :)
...and besides, "templates" fall far short of "design patterns" even on a good day :)