Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the advantage of using FAST_FORWARD for defining a cursor?

Tags:

What is the advantage of using FAST_FORWARD for defining a cursor? Is it better for performance? why?

like image 269
masoud ramezani Avatar asked Feb 17 '10 12:02

masoud ramezani


People also ask

What is the purpose of using cursor?

A cursor keeps track of the position in the result set, and allows you to perform multiple operations row by row against a result set, with or without returning to the original table. In other words, cursors conceptually return a result set based on tables within the databases.

Why is using a cursor sometimes helpful for applications processing database information?

Cursors are used by database programmers to process individual rows returned by database system queries. Cursors enable manipulation of whole result sets at once. In this scenario, a cursor enables the sequential processing of rows in a result set.

Why should we use cursor in SQL Server?

A SQL Server cursor is a set of T-SQL logic to loop over a predetermined number of rows one at a time. The purpose for the cursor may be to update one row at a time or perform an administrative process such as SQL Server database backups in a sequential manner.


1 Answers

The definition from MSDN is:

Specifies a FORWARD_ONLY, READ_ONLY cursor with performance optimizations enabled. FAST_FORWARD cannot be specified if SCROLL or FOR_UPDATE is also specified. FAST_FORWARD and FORWARD_ONLY are mutually exclusive; if one is specified the other cannot be specified.

I've boldened the key bit. It can support these "performance optimisations" because it does not need to support multi-direction iterating through the cursor (FORWARD_ONLY) and does not support modifications (READ_ONLY).

Of course, if you don't really need to use a cursor at all - then using a cursor even with this option is not going to perform as well . If you can do the same task using a set-based approach, do that instead - this is the bit I really wanted to stress.

like image 129
AdaTheDev Avatar answered Oct 03 '22 15:10

AdaTheDev