how to change my thinking process for sql.

If I am working with the technology that is using different approach than sql. How to modify my mind to think in that direction?

For example, if i am working with java. I am thinking about object. And if I am working with sql i have to think about set. But how?

more ▼

asked May 12, 2010 at 09:01 AM in Default

Dharmendra gravatar image

44 7 7 7

(comments are locked)
10|1200 characters needed characters left

4 answers: sort voted first

One word - Practice.

Practice and Testing.
Ok, Two words, Practice, Testing and Reading.
Right, Three words, Practice, Testing, Reading and Application...

Practice using TSQL in a set based way,
Test what you create in a set based way against an iterative method
Read about set based solutions
Apply the above to the data and databases that you are working with.

Any search for "Tally Table" or "Numbers Table" or "Jeff Moden" will be a great place to start. He has some great articles on www.SQLServerCentral.com.

more ▼

answered May 12, 2010 at 09:08 AM

Fatherjack gravatar image

Fatherjack ♦♦
42.7k 75 79 108

+1 for the Spanish Inquisition.
May 12, 2010 at 09:17 AM Grant Fritchey ♦♦
practice is more important thing, i think i will learn as i am wirking with sql.
May 12, 2010 at 09:42 AM Dharmendra
I second the recommendation for Jeff Moden's articles, and add Joe Celko's (see simple-talk.com amoungst other places for some). Those two authors do perhaps the best job of helping people learn to switch to set based thinking.
May 12, 2010 at 11:08 AM TimothyAWiseman
Oh my... you good folks certainly have me blushing. Thank you for your good thoughts... I'm truly humbled.
May 14, 2010 at 07:53 PM Jeff Moden
(comments are locked)
10|1200 characters needed characters left

I agree with the above, but here is something that might help you think about it.

Java is a 3GL (Third generation language), same as C#, VB.NET etc. In a 3GL you tell the computer how to do what it is you're asking it to do.

SQL is a 4GL (Fourth generation language), and the idea with a 4GL is that you tell the computer what it is that you want.

Putting that in a more human scenario - Imagine you have a factory which makes widgets. You have workers in that factory that follow a set of instructions on how to make a widget. These instructions were created by somebody who looked at the specification of what a widget was, and decided how to make it. The instructions are the 3GL, the specification is the 4GL. Try to think about what it is you're trying to achieve, rather than how to achieve it.

That having been said, you will learn, over time, that you need to help SQL along it's way, and give it some hints as to how. You can read some more about it here...

more ▼

answered May 12, 2010 at 12:48 PM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.4k 61 65 87

(comments are locked)
10|1200 characters needed characters left

As hard as it is, don't think about how to get what you want, think about what you want. Think about the columns that you want to retrieve, not the rows. Every time you find yourself starting to write a cursor, stop. Then try to wrap your head around how you could do the same thing with a set operation.

That's about the best advice I can offer. Other than that, I'd suggest reading Itzik Ben Gan's books on TSQL. There just isn't a better place to get started on the understanding of what's happening when you write a query.

more ▼

answered May 12, 2010 at 09:20 AM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
101k 19 21 74

+1 - great reading source and sound advice to avoid using the C word.
May 12, 2010 at 09:32 AM Fatherjack ♦♦

+1 for how to think. I even have it in my signature line on SQLServerCentral...

First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
May 14, 2010 at 07:50 PM Jeff Moden
Heck Jeff, that's probably where I got it originally.
May 17, 2010 at 10:47 AM Grant Fritchey ♦♦
(comments are locked)
10|1200 characters needed characters left

Read the best practices and stick to it for some time and you will get a hang of it slowly.

more ▼

answered May 12, 2010 at 01:51 PM

Bhaskar gravatar image

333 16 17 20

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: May 12, 2010 at 09:01 AM

Seen: 2536 times

Last Updated: May 12, 2010 at 11:06 AM