x

What is a #Cursor

Seeder question

This is a Regular Cursor

Declare MyCursor cursor for
Select Id, Name 
From Customer

This is a #Cursor

Declare #MyCursor cursor for
Select Id, Name 
From Customer

Questions:

  1. What is the difference?
    • Is one preferred over the other?
    • Is it the same difference as in a TABLE and a #TABLE?
more ▼

asked Mar 19 '10 at 03:38 PM in Default

Raj More gravatar image

Raj More
1.7k 77 82 84

+1 - nice seeder q
Mar 19 '10 at 04:11 PM Matt Whitfield ♦♦
Excellent question.
Mar 19 '10 at 04:31 PM Grant Fritchey ♦♦
Nice question. Not sure I know that this is anything more than a naming convention. I typically declare cursors with an @ symbol. In the rare occasion that I use a cursor.
Mar 19 '10 at 07:10 PM CirqueDeSQLeil
(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

I believe the origin of this goes back to Pandora. When she opened the box, the ills and mischief of man and all that is evil spilled out, leaving only one thing left in the box--that thing was not a cursor...

more ▼

answered Mar 19 '10 at 09:10 PM

Scot Hauder gravatar image

Scot Hauder
5.9k 13 15 18

Awesome answer.
Mar 20 '10 at 01:56 AM TimothyAWiseman
+1 - epic suggestion, off to update wikipedia's Pandora's Box entry ...
Mar 20 '10 at 07:41 AM Fatherjack ♦♦
(comments are locked)
10|1200 characters needed characters left

I believe this just to be a naming convention and a matter of preference. If I use a cursor I use the following:

Declare @MyCursor cursor for Select Id, Name From Customer 
more ▼

answered Mar 19 '10 at 07:13 PM

CirqueDeSQLeil gravatar image

CirqueDeSQLeil
4k 10 11 15

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x977
x57
x27

asked: Mar 19 '10 at 03:38 PM

Seen: 1432 times

Last Updated: Mar 26 '10 at 02:51 PM