Hi
What are Cursors. Explain different types of Cursors. What are the disadvantages of Cursors. How can you avoid Cursors ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted May 10, 2012, 1:16 AM
Cursor is used for row-by row operations. The cursor is so named because it indicates the current position in the resultset.
A cursor is a set of rows together with a pointer that identifies a current row.
In other word, Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, its like recordset in the ASP and visual basic.
Types of Cursors:
1.Forward-only cursor do not support scrolling, they only support fetching rows serially from the start to end.
2.Static cursors are built in tempdb when the cursor is opened. They never reflect changes to the data. Static cursors are always read only, because it is built as a work table in tempdb.
3.Keyset driven cursors have the membership and order of rows in the result set fixed when the cursor is opened.
4.Dynamic cursors are the opposite of static cursors. Dynamic cursors reflect all changes made to the rows in their result set. The data values, order and membership of the rows in the result set can change on each fetch.
pls refer this url
http://www.sqlinfo.in/2011/04/sql-server-cursor-simple/
http://www.mssqlcity.com/Articles/General/UseCursor.htm
thanks
If this post is useful then mark it as "Accepted Answer"
Jignesh TrivediPosted May 10, 2012, 12:05 AM
Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis.
plese refer http://www.mssqltips.com/sqlservertip/1599/sql-server-cursor-example/ it is very good article.
type of corsor refer
http://technet.microsoft.com/en-us/library/ms172375.aspx
hope this help.
Satyapriya NayakPosted May 9, 2012, 10:24 PM
Cursors allow row-by-row prcessing of the resultsets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
Most of the times, set based operations can be used instead of cursors.
Please refer the below link for the example of Types of cursors
http://www.dotnet-tricks.com/Tutorial/sqlserver?id=RLID060512&title=SQL%20Server%20-%20Types%20of%20Cursors
Thanks