20

Is there such a thing as Design Patterns in SQL ???

3
  • 3
    Does this refer to DB design or patterns for queries? Commented May 6, 2010 at 20:49
  • 1
    If you're talking about how to write a select statement for a certain scenario then I totally hear you on this question. Commented Oct 27, 2010 at 23:10
  • Joe Celko's SQL Programming Style Commented Apr 30, 2012 at 20:09

3 Answers 3

12

A design pattern is simply a recognised way of solving a problem that works in different specific circumstances. Do such things exist in SQL? Of course - for example implementing many to many relationships between two tables using a third table.

Sign up to request clarification or add additional context in comments.

Comments

11

Yes. :)

SQL Design Patterns: Expert Guide to SQL Programming

(Not even sure if this is a recommended book.. just illustrating that "proper design" exists).

3 Comments

I live in a universe of "improper design" in both the host side(.NET) and database side(MS SQL SERVER). I am just wondering if I will ever get to work in an evironement where fellow programmers DON'T take pride in shunning books and "GETTING THE JOB DONE".
You and me both my man. We are constantly balancing results vs. good OO code. Seems like one or the other always has to suffer...
This book costs as much as a SQL Server License
7

You may want to look at database normalization which is some sort of general Design Pattern in SQL.

3 Comments

There is also a SQL 'anti-pattern' book coming soon. pragprog.com/titles/bksqla/sql-antipatterns
And I've looked at two chapters of said book, and at this point, it's got some magnificent errors in it. The following from the book is supposed to fetch a random row from a table in Oracle, and it's got two showstopper errors in it: $offset = $pdo->query("SELECT dbms_random.value(1, (SELECT COUNT(*) FROM Bugs) AS offset FROM dual)")->fetch(); $stmt = $pdo->prepare("SELECT * FROM Bugs WHERE ROWNUM = :offset" ); $stmt->execute( $offset ); $rand_bug = $stmt->fetch();
SQL design pattern is different from Database Design Pattern. SQL design pattern is about programming, not database design.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.