title: Pros and cons of using a cursor (in SQL server)
body: <p>I asked a question here <a href="https://stackoverflow.com/questions/9316550/using-cursor-in-oltp-databases-sql-server">Using cursor in OLTP databases (SQL server)</a></p>
  <p>where people responded saying cursors should never be used.</p>
  <p>I feel cursors are very powerful tools that are meant to be used (I don't think Microsoft supports cursors for bad developers).Suppose you have a table where the value of a column in a row is dependent on the value of the same column in the previous row. If it is a one time back end process, don't you think using a cursor would be an acceptable choice?</p>
  <p>Off the top of my head I can think of a couple of scenarios where I feel there should be no shame in using cursors. Please let me know if you guys feel otherwise.</p>
  <ol>
  <li>A one time back end process to clean bad data which completes execution within a few minutes.</li>
  <li>Batch processes that run once in a long period of time (something like once a year).</li>
  </ol>
  <p>If in the above scenarios, there is no visible strain on the other processes, wouldn't it be unreasonable to spend extra hours writing code to avoid cursors? In other words in certain cases the developer's time is more important than the performance of a process that has almost no impact on anything else.</p>
  <p>In my opinion these would be some scenarios where you should seriously try to avoid using a cursor.</p>
  <ol>
  <li>A stored proc called from a website that can get called very often.</li>
  <li>A SQL job that would run multiple times a day and consume a lot of resources.</li>
  </ol>
  <p>I think its very superficial to make a general statement like &quot;cursors should never be used&quot; without analyzing the task at hand and actually weighing it against the alternatives.</p>
  <p>Please let me know of your thoughts.</p>