Updating the records in to the cursor

Posted by / 20-Jul-2019 02:28

Updating the records in to the cursor

Requirements: If the update-table does not have a Primary Key, the cursor is read-only.

Keep in mind that SQL Server is designed around batch processing, so the less you loop, the faster your system will run.In this tip, I'll share some alternatives to cursors that provide looping functionality.Method 1: Temp table with identity column In the first approach, we will use a temp table with an identity column added to allow for row-by-row selection.Usage: if you replace “WHERE current of curs” by any “WHERE x = y” statement, it would decrease performance dramtically.During a test with 80000 records, execution time without update cursor takes 20 minutes.

updating the records in to the cursor-57updating the records in to the cursor-60updating the records in to the cursor-43

ABOUT THE AUTHOR Matthew Schroeder is a senior software engineer who works on SQL Server database systems ranging in size from 2 GB to 3 TB, with between 2k and 40 k trans/sec. Schroeder for taking the time to write these articles.