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

avatar image

44 7 7 10

(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

avatar image

Fatherjack ♦♦
43.8k 79 101 118

(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

avatar image

Matt Whitfield ♦♦
29.5k 62 66 88

(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

avatar image

Grant Fritchey ♦♦
137k 20 46 81

  • great reading source and sound advice to avoid using the C word.

May 12, 2010 at 09:32 AM Fatherjack ♦♦
  • 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

avatar image

333 17 19 24

(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.

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: 2768 times

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

Copyright 2018 Redgate Software. Privacy Policy