We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,571 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

What is cursor in SQL and when to use

What is cursor in SQL and when to use

3
Contributors
2
Replies
16 Hours
Discussion Span
6 Months Ago
Last Updated
4
Views
pratham3090
Newbie Poster
8 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

A cursor is basically a table, generated from a query, so you can iterate through the rows. It is usually used in a stored procedure or trigger.

pritaeas
Posting Prodigy
Moderator
9,542 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98

A cursor is the tool we've got to iterate through records.
You can loop through the results of your query and do whatever you have to do with each record.
I've got to disagree with pritaeas on the sp or triggers part. You use a cursor when you need to handle each record differently, in a specific order where a case won't cover things. Usually they are too expensive (in terms of resources) and don't get the job done as fast as processing bulk data would.

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.3659 seconds using 2.65MB