For some people, it’s the wrong question. SQL CURSOR IS the mistake. The devil is in the details! You can read all sorts of blasphemy in the entire SQL blogosphere in the name of SQL CURSOR.

If you feel the same way, what made you come to this conclusion?

If it’s from a trusted friend and colleague, I can’t blame you. It happens. Sometimes a lot. But if someone convinced you with proof, that’s a different story.

We haven’t met before. You don’t know me as a friend. But I hope that I can explain it with examples and convince you that SQL CURSOR has its place. It’s not much, but that small place in our code has rules.

But first, let me tell you my story.

I started programming with databases using xBase. That was back in college until my first two years of professional programming. I’m telling you this because back in the day, we used to process data sequentially, not in set batches like SQL. When I learned SQL, it was like a paradigm shift. The database engine decides for me with its set-based commands that I issued. When I learned about SQL CURSOR, it felt like I was back with the old but comfortable ways.

But some senior colleagues warned me, “Avoid SQL CURSOR at all costs!” I got a few verbal explanations, and that was it.

SQL CURSOR can be bad if you use it for the wrong job. Like using a hammer to cut wood, it’s ridiculous. Of course, mistakes can happen, and that’s where our focus will be.

#sql server #sql cursor #sql functions #sql

Do You Make These Mistakes When Using SQL CURSOR?
1.15 GEEK