CURSORS SQL

---CURSORS---

---Using cursors, we can retreive the first, next, previous,last rows in a resultset as well as the rows at  a particular position.

--We can also see the current data and previous data  using cursors.


--TYPES OF CURSORS:--

----1)KeySet Cursors
----2)Dynamic cursors
----3)Forward_only cursors.


---KeySet Cursors:--Used to view first, last, previous, next rows in a resultset.

----We can also view rows at a particular position.
----Data Changes cannot be viewed using KeySet Cursors.


----Dynamic Cursors:-Used to view first,last, previous, next rows in a resultset.
    --Rows at a particular position cannot be viewed. Data changes can be viewed.


---Forward_only cursors:-Only next rows can be seen.
    --First, Previous, last rows cannot be viewed, data changes cannot be seen

create table EmpMaster
(eno int primary key,
ename varchar(10))

--insert EmpMastervalues(200,'cd')
select * from EmpMaster
Create procedure curproc
as
declare
@a int,
@b varchar(10)
declare abc cursor keyset for select eno, ename from EmpMaster
open abc
/*fetch first from abc into @a, @b
print Convert(Varchar(10),@a)+' '+@b
fetch next from abc into @a, @b
print Convert(Varchar(10),@a)+' '+@b*/

fetch last from abc into @a,@b
print Convert(Varchar(10),@a)+' '+@b
insert EmpMaster(eno,ename) values(1679,'cv')
fetch last from abc into @a,@b
print Convert(Varchar(10),@a)+' '+@b
/*fetch absolute 3 from abc into @a,@b
print Convert(Varchar(10),@a)+' '+@b*/
close abc
deallocate abc
CURSORS SQL Reviewed by Rupesh on 19:45 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.