How to write for-loop like code in SQL

I needed to dynamically generate missing items in database. I had a list of Sports and Categories, and I needed to generate items with all combinations of these two entities. But some of them already existed in database, so those should be skipped. My idea was to perform kind of for-each loop iterating over the Sports collection, but written in SQL. In each iteration I would check if given combination already exist in DB and if not, I create it. SQL Cursor comes to help If you run into issues with another coding technique and need to get something done …

Continue Reading