Darrell Norton's Blog [MVP]

Sponsors

The Lounge

News

  • Darrell Norton pic

    MVP logo

    View Darrell Norton's profile on LinkedIn

    Currently Reading:

    weewar.com

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Set-Based Thinking for SQL Server

As I was working on several solutions to a database query, I sent an email to a friend that is an excellent DBA-Developer for help.  He knows databases very well, both querying and administration, and can still code (a rare combination).  At first I was trying to use a user-defined function (UDF) which abstracted out the logic of what I needed to do and all this other programmer-related buzzword stuff.  He showed me two other ways to try, both using the set-based nature of SQL.  Having had significant exposure to SQL development before, I had one of those "duh" moments.

Then it occurred to me that one of the problems many programmers have is adjusting to set-based thinking.  With our heads down pounding out code, we get used to sequential thinking.  Even object-oriented code, within each method or event, is sequential.  You start at the beginning of the method, do this and that, and return some result.  Sequentially-based thinking.  Set-based thinking is often only encountered when a developer accesses a database.  Considering the majority of actions are simple CRUD (Create, Read, Update, and Delete), many will never make the transition to set-based thinking because they get no exposure to it.  This can often lead to performance-challenged solutions.

To prevent any of the intelligent readers of DotNetJunkies or my blog (all 2 of you!) from being unskilled and unaware of it, I went looking for some decent explanations from someone reputable. There is the book Joe Celko's SQL for Smarties (Amazon Associates link), which I highly recommend if you are going to develop serious database-backed applications. Itzik Ben-Gan, T-SQL Black Belt for SQL Server Magazine, constantly preaches finding a set-based solution.  Select articles are Set Members and Relationships (first in a series), Sequential to Set-Based, and Matching Transactions.


Posted 06-19-2003 11:24 AM by Darrell Norton

[Advertisement]

Comments

Ngan Trinh wrote re: Set-Based Thinking for SQL Server
on 06-23-2004 4:14 PM

i want to search a book in sql