473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

What is a cursor?

I had a friend write a stored procedure to perform a function for one
of my clients. What he wrote doesn't fully do what I need, and I hope
to finish it myself. I have programming sense, but not so much with
SQL.

I'm trying to figure out the code, and he has used something called a
"cursor." I'm not sure whether this is an SQL construct or a structure
that he has just labeled "cursor." My guess is that it is an SQL
construct. Can anyone give me a quick run down of how this works?

sincerely,
Tyler H.
-----------------------------------------------
<a href="http://www.seearoomhawaii.com/bed-breakfasts/">bed &
breakfasts in Hawaii</a>
Jul 20 '05 #1
2 1569
Cursors are a method of processing data row-by-row, usually in a loop. See
DECLARE CURSOR in Books Online for details and examples.

In SQL Server cursors are usually slow and inefficient compared to other
methods of manipulating data. Most of the time cursors are not necessary and
good SQL developers will avoid them where they can.

You don't say what this cursor code is doing. Maybe your code is performing
some operation that is inherently procedural in nature - such as sending an
email for each row in a table. If that's the case then a cursor is a
reasonable solution. On the other hand if the cursor is just manipulating
data then chances are there are much simpler / better / faster
alternatives - that's not always the case but 99% it is so.

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
See SQL Books Online for a full explanation, but think of it as a pointer to
a set of rows that depending on the options called can move forwards or
backwards through the set.

In general, cursors are an inefficient last ditch effort that should be
avoided for both performance and locking reasons. TSQL is a set oriented
language and again another generality when coded in a set oriented way will
out perform row oriented approaches.

The SQL group in this news group is pretty good about helping out if you
post an explanation of the issue, the object creation, and data insert
scripts for testing.

Danny

"Tyler H." <se************@resonant.com> wrote in message
news:53**************************@posting.google.c om...
I had a friend write a stored procedure to perform a function for one
of my clients. What he wrote doesn't fully do what I need, and I hope
to finish it myself. I have programming sense, but not so much with
SQL.

I'm trying to figure out the code, and he has used something called a
"cursor." I'm not sure whether this is an SQL construct or a structure
that he has just labeled "cursor." My guess is that it is an SQL
construct. Can anyone give me a quick run down of how this works?

sincerely,
Tyler H.
-----------------------------------------------
<a href="http://www.seearoomhawaii.com/bed-breakfasts/">bed &
breakfasts in Hawaii</a>

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rob Gudgeon | last post by:
Hi everyone Can anybody give me a decent explanation of what ora_bind is supposed to do? I assumed it did the same sort of thing as Perl's DBI bind_columns function ie. as each column is...
7
by: Brian Kelley | last post by:
I am trying to use threads and mysqldb to retrieve data from multiple asynchronous queries. My basic strategy is as follows, create two cursors, attach them to the appropriate databases and then...
3
by: robert | last post by:
Mr. Kyte's article doesn't use cursors, while Mr. Feuerstein's book examples do. my recollection of conventional wisdom is to avoid using cursors. is this difference merely a question of style,...
1
by: Csaba2000 | last post by:
I'm probably just blanking today, but, how can I find out what type the cursor currently is? Is document.activeElement.style.cursor the way to go on this? But that's only for IE, right? Thanks...
12
by: Kevin Blount | last post by:
I'm playing with dragable <DIV>s, being inspired by google.com/ig, where you can move items on the page around and have items you move over change position if necessary. I have 3 div's setup,...
2
by: dave | last post by:
In my form Ive got a SaveData() routine that saves changes to a DB. When I encounter an exception in the save operations, I am having trouble chaning the cursor back to the default cursor, it just...
10
by: Just Me | last post by:
Does Me.Cursor.Current=Cursors.WaitCursor set the current property of Me.Cursor to Cursors.WaitCursor And Me.Cursor.Current=Cursors.Default set the Me.Current property to something (default)...
2
by: Jim Frazer | last post by:
Hi, I'm working on an application in C# that will allow the user to create simple CAD drawings on a CEPC system. I would like to be able to change the cursor shape depending on the drawing mode...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
0
debasisdas
by: debasisdas | last post by:
RESTRICTIONS ON CURSOR VARIABLES ================================= Currently, cursor variables are subject to the following restrictions: Cannot declare cursor variables in a package spec. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.