What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14483 |  Welcome, Guest!   Register  Login
 Home > Blogs > SQL Server > Cursor ...
Sabarimahesh

Cursor

 Blog author: Sabarimahesh | Posted on: 3/23/2012 | Category: SQL Server Blogs | Views: 1158 | Status: [Member] | Points: 75 | Alert Moderator   


WHAT IS CURSOR ??:
  • Cursor is a Database Objects
  • Cursor Performs Row By Row Basis
  • Cursor Define a Result in Set of Data Row
  • Cursor Points a Row in Set of  Row
  • Cursor Refers Only One Row at a Time

WHAT CURSOR PERFORMS ??:

  • Declare cursor
  • Open cursor
  • Fetch row from the cursor
  • Process fetched row
  • Close cursor
  • De-allocate cursor

ADVANTAGE:

  • Cursor is like Data type  used to define  multi-value variable,

    When we declare Static variable (ex: int a) it holds only one value,

    But declaring cursor we can Hold Multi-value (Ex: Select Id From emptbl) 

DISADVANTAGE:

  • This affects the Performance to become less

SYNTEX:

DECLARE CURSOR_NAME CURSOR

QUERY DESCRIPTION:

DECLARE CURSOR:

 

Two Ways to Declare

  1. DECLARE @id INT
  2. DECLARE @ getid CURSOR SET @getid = CURSOR FOR select id from cidtbl

(OR)

 

      DECLARE getid CURSOR FOR select id from cidtbl

 

OPEN CURSOR:

OPEN @getid

FETCH ROW FROM THE CURSOR

FETCH NEXT

FROM @getid INTO @id

WHILE @@FETCH_STATUS

BEGIN

PRINT @id

FETCH NEXT

FROM @getid INTO @id

END

CLOSE CURSOR

CLOSE @getid

DE-ALLOCATED CURSOR 

DE-ALLOCATED   @getid

Using the code

DECLARE @id INT

DECLARE @ getid CURSOR SET @getid = CURSOR FOR select id from cidtbl

OPEN @getid

FETCH NEXT

FROM @getid INTO @id

WHILE @@FETCH_STATUS

BEGIN

PRINT @id

FETCH NEXT

FROM @getid INTO @id

END

CLOSE @getid
DE-ALLOCATED   @getid 


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M
Found interesting? Add this to:



 More Blogs from Sabarimahesh

     More ...

    Experience:1 year(s)
    Home page:http://www.dotnetfunda.com
    Member since:Thursday, March 15, 2012
    Level:Bronze
    Status: [Member]
    Biography:C#,ASP.NET, JAVA SCRIPT,SQL, J QUERY,MVC 3

     Responses

    Alok
    Posted by: Alok | Posted on: 1/18/2013 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

    Can we Call this Cursor from Front End...

    Thanks & Regards,
    Alokssm

    >> Write Response - Respond to this post and get points

    More Blogs

    About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
    General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
    Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 4:03:40 AM