StatCounter

View My Stats

Tuesday, February 5, 2008

Types Of Cursor-SQL Server

1.Insensitive Cursor
2.Scroll Cursor
3.Forward-Only
4.Static Cursor
5.Keyset Cursor
6.Dynamic Cursor


1.Insensitive Cursor:
Insensitive cursor Example without using the looping structure

select * from table1

declare cursor_table1 insensitive cursor for select name1,salary from table1//Cursor declaration

create procedure p_table1 as
declare @name1 varchar(50)declare @salary integer
open cursor_table1 fetch next from cursor_table1 into @name1,@salary print @name1 print @salaryclose cursor_table1


exec p_table1

2.Scroll Cursor:

In This scroll cursor we can have more options method compared to insensitive cursor.
AN insensitive cursor have just a
1.Fetch next statement

But for Considering the scroll cursor have more as indicated below
1.fetch next
2.fetch first
3.fetch last
4.fetch Relative
5.fetch absolute

One important things is we cant able to update the cursor


simple example if the scroll cursor declaration as given below


declare cursor_table3 scroll cursor for select name1,salary from table1


3.Forward only cursor:

This forword only cursor is nothing but the fetching of records are moved from
first to the last.

It support fetch next function

Each time the fetch status is evaluated is (Under this type of situation we are using
Static and keyset cursor)


Delete a Cursor:

Deallocate CursorName

No comments: