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?
One word - Practice.
Practice and Testing.
Practice using TSQL in a set based way,
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.
answered May 12, 2010 at 09:08 AM
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...
answered May 12, 2010 at 12:48 PM
Matt Whitfield ♦♦
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.
answered May 12, 2010 at 09:20 AM
Grant Fritchey ♦♦
Read the best practices and stick to it for some time and you will get a hang of it slowly.
answered May 12, 2010 at 01:51 PM