Thursday, May 31, 2012

Difference between Set-Based approach and Cursor-Based approach in SQL Server ?

Think of it this way. If your wife wants you to fold the washing that's come out of the tumble dryer - she might well say 'can you please fold the washing?'. That's a set based approach - it's an operation over a collection of items.
The cursor based approach would be the equivalent of your wife asking you to fold a t-shirt, then when you had come back with that asking you to fold a pair of trousers, then when you had come back with that, asking if you could fold a jumper. No doubt, that would really hack you off. SQL Server doesn't fare much better, and really prefers to be asked to do things the set based way.

When working in T-SQL, try to tell the system what you want to do with the data, not how you want it done.

No comments:

Post a Comment