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?
Answer by Fatherjack ·
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.
Answer by Matt Whitfield ·
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...
Answer by Grant Fritchey ·
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.