all groups > sql server programming > september 2005 >
You're in the

sql server programming

group:

Cursor in MS Yukon / SQL 2005.


Cursor in MS Yukon / SQL 2005. hitendra15 NO[at]SPAM gmail.com
9/18/2005 11:40:48 PM
sql server programming: Is Cursor Included in Yukon/SQL 2005. or any alternet solution for that?
Re: Cursor in MS Yukon / SQL 2005. David Portas
9/19/2005 12:00:00 AM
Yes 2005 still supports cursors. There is already an alternative solution in
earlier versions: set-based SQL code. If you tell us what you want to do
then we might be able to give you a specific solution.

--
David Portas
SQL Server MVP
--

Re: Cursor in MS Yukon / SQL 2005. hitendra15 NO[at]SPAM gmail.com
9/19/2005 1:33:12 AM
Thanks for your reply.......

Just i want to know MS has included cursor in Yukon? if yes then any
new feature in cursor? and if no what is the alernet solution for that
thats what i wanted to know.....

-------------
HItendra
Re: Cursor in MS Yukon / SQL 2005. David Portas
9/19/2005 2:58:03 AM
I'm not aware of any new features of cursors in 2005 but then I haven't
looked for them. If it's important to you then the best place for that
question is the SQL Server 2005 beta newsgroups.

Cursors are almost never necessary in SQL Server and they are seldom a good
idea. Since you haven't told us what you want to do I can't tell you what the
alternatives are. "Cursor" is not a specification of a problem - it's just
one type of solution. The better solutions are usually set-based. Set-based
statements operate on the whole set of rows (like SELECT/UPDATE/DELETE/INSERT
statements) instead of one row at a time (like a cursor). Most of the time it
pays to find a set-based solution rather than a cursor because set-based code
is generally easier to develop, test, support and maintain as well as being
much more efficient than most cursor solutions.

--
David Portas
SQL Server MVP
--

[quoted text, click to view]
Re: Cursor in MS Yukon / SQL 2005. David Portas
9/19/2005 4:30:03 AM
[quoted text, click to view]

Fine example, but is it legal in any jurisdiction you know of?

As you've mentioned, iteration is a feature of cursors and we do have new
non-cursor features in SQL2005 that are relevant to those types of problem.
The CROSS APPLY operator means we no longer need to use cursors for expanding
an adjacency list and similar tasks. Also, the ROW_NUMBER function is a
convenient way to implement sequences over data. So there should be even less
reason to use cursors in SQL2005.

--
David Portas
SQL Server MVP
--
RE: Cursor in MS Yukon / SQL 2005. Cowboy (Gregory A. Beamer) - MVP
9/19/2005 6:01:02 AM
Yes, cursors are included in SQL 2005. I do not know of any new features of
cursors. They are not the preferred way of doing work (since SQL 7.0), so I
do not use them unless I absolutely have to. This follows MS suggestions and
may be the reason cursors do not change much.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


[quoted text, click to view]
Re: Cursor in MS Yukon / SQL 2005. --CELKO--
9/19/2005 6:34:38 AM
Yes, they have cursors, but if you had been writing good SQL, you would
not be using them more than a few times in 10-20 years of production
coding anyway.
Re: Cursor in MS Yukon / SQL 2005. Erland Sommarskog
9/19/2005 11:08:22 AM
(hitendra15@gmail.com) writes:
[quoted text, click to view]

There are no new features with cursors, as far as I know. The version
with the feature-craze on cursors was SQL 7, and I still haven't understood
all of that. Keep your cursors INSENSITIVE, STATIC or FAST_FORWARD, and
stay away from the default keyset cursors.

[quoted text, click to view]

Rather cursors are the alternate solution when you simply cannot find a
set-based solution. That happens, but it is not that frequent. Here is a
quick example of a set-based solution. Say that you have an employee
table, and you are to update the salaries. Generally there is a two
percent increase, but staff that earns less than 15000 SEK/month gets
300 SEK extra, and all women receive an extra 0.5% raise. This can be
done in one UPDATE:

UPDATE employees
SET salary = 1.02 * salary +
CASE WHEN salary < 15000 THEN 300 ELSE 0 END +
CASE sex WHEN 'K' THEN 1.005 * salary ELSE 0 END

Ah, when I think of it, if you really like iterattion, yes there is now
a new way to do this in SQL 2005, as you now can write stored procedures
in a .Net language such as C#. This gives new oppurtunities to implement
good solutions in SQL Server - and also a lot of new oppurtunities to
implement really poor solutions if implemented improperly.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Re: Cursor in MS Yukon / SQL 2005. Erland Sommarskog
9/19/2005 10:05:39 PM
David Portas (REMOVE_BEFORE_REPLYING_dportas@acm.org) writes:
[quoted text, click to view]

Interesting question. If an employer over here would do this, but give the
extra raise to men, there would be one h*ll of a noise. But for women?
My guess, is that they would get away with it. Even more so, if this was
the result of negotiations with the union. Oh, well, wrong newsgroup
I think.

[quoted text, click to view]

Great examples!

Of what I can think of, left is the case when you have a stored procedure
which you want to reuse, and you don't find it worth the effort to
rewrite the stored procedure for handle an input set. And then of course
the few exceptional cases where cursors actually are faster.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Re: Cursor in MS Yukon / SQL 2005. hitendra15 NO[at]SPAM gmail.com
9/20/2005 4:29:52 AM
thank you guys i understood that there is a cursor but its not improved
no new features to it,
so it seems me that Procedures, UDT, Functions, triggers etc are Part
of SQL CLR[We can make], cursor is not.....am i correct?

-------------
Hitendra
AddThis Social Bookmark Button