Cursor V/S query

  • Hey all

    i have a job that can be done using the following ways:

    1) using Cursors

    2) using a Single Query that includes both a    insert and select statements

    which is the best method and most performance enhancing way and why?

    thanx

    Rajiv.

  • If you can do it using a single query then why bother with a cursor?

    SQL Server is optimised for set based operations.  I tend to view cursors as an option of last resort.  You can get locking problems with them because they itterate through recordsets on a row by row basis.

    If you are worried that a single query would be too punishing i.e. updating 1,000,000 rows at a time then you can break the job down into smaller chunks by being careful with your WHERE clauses and/or including SET ROWCOUNT

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply