Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is the primary purpose of a cursor?

Posted on 2013-02-07
2
Medium Priority
?
155 Views
Last Modified: 2013-02-07
I am new to MS Sql and trying to figure out cursors.  Please feel free to elaborate on my question in order to provide a clear understanding.
0
Comment
Question by:rhservan
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38865761
usually, people use cursors when they (think they) cannot do it in a single SQL statement.
there are indeed situations where you need to handle 1 row at a time (for example, sending emails based on a query)
however, still a non-cursor solution is then possible and almost always better performîng ...
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 38866870
Microsoft SQL Server statements produce a complete result set, but there are times when the results are best processed one row at a time. Opening a cursor on a result set allows processing the result set one row at a time. You can assign a cursor to a variable or parameter with a cursor data type.

http://msdn.microsoft.com/en-us/library/ms181441(v=sql.100).aspx

Use of cursors is normally associated with "procedural code" (e.g. allows branching)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question