什么是sql中的游标??? [英] what are cursors in sql???

查看:82
本文介绍了什么是sql中的游标???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是sql的新手并需要游标方面的帮助吗?

他们是什么以及他们如何以及为什么使用它们?

它会很友好如果有人在这方面帮助我..

问候

vishal jain。

解决方案

vishal写道:

我是sql的新手并且需要游标方面的一些帮助?
它们是什么以及它们如何以及为什么用于它们?

如果有人在这方面帮助我,那就太好了..

问候
vishal jain。




游标是数据结构,允许您一次操作一行查询

a的结果。通常我们只在客户端中执行此操作

应用程序代码而不是在SQL中。这是因为它通常要快得多,

使用基于集合更容易,更简洁,更易于维护。 SQL代码

- 在

时间内操纵整个数据集而不是一行的代码。


如果你是新的到SQL然后我的建议是你忽略游标,直到

你获得了更多基于集合的SQL代码的专家。虽然对于他们来说肯定是合法的用途,但游标经常被严重误用了,而没有经验的人也不会更好地误用游戏。只有当你有很多

和很多真实经验时SQL你会有意识到,当光标是一个合适的解决方案时,
会识别出来。


这可能听起来不是一个非常有用的答案,但如果你考虑到这一点

可能至少是普通SQL开发人员所能做到的99%

没有光标你会意识到还有更多

首先要学习的重要事项。


-

David Portas,SQL Server MVP


请尽可能发布足够的代码来重现你的问题。

包含CREATE TABLE和INSERT语句通常会有所帮助。

说明你正在使用的SQL Server版本并指定内容

任何错误消息。


SQL Server联机丛书:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx

-


有趣的拍摄游标。

我从未在客户端代码中使用过游标。看起来非常低效。

通过网络传递所有内容,并保持光标打开,直到

客户端cpu可以处理它。


我在存储过程中广泛使用了游标。


光标是最后的选择。尽可能使用基于设置的

解决方案。但如果你必须逐步处理每个记录,

有时这是唯一的方法。


Doug写道:< blockquote class =post_quotes>有趣的游标。
我从未在客户端代码中使用过游标。在网上传递所有内容并将光标保持打开直到
客户端cpu可以处理它为止,这似乎效率很低。


这是真的。通常,大多数处理应该在服务器上进行。我不想暗示其他情况。
并不意味着暗示。客户端记录集是各种各样的游标,这就是我所指的。

我在存储过程中广泛使用了游标。




真的吗?对于大多数生产任务,我会说超过99%的数据可以在没有光标的情况下完成。当然,如果你制作

广泛的话。使用游标然后我建议你应该寻找更好的解决方案。除非你写了很多

元数据管理或管理流程,否则就是这样。例如,我认为在过去的6年里,我已经写了3或4个游标,而且所有这些游戏都是为了支持
DBA类型的任务。


-

David Portas,SQL Server MVP


请尽可能发布足够的代码来重现您的问题。

包含CREATE TABLE和INSERT语句通常会有所帮助。

说明您正在使用的SQL Server版本,并指定任何错误消息的内容




SQL Server联机丛书:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx

-


I am new to sql and require some help on cursors?
what are they and how and why are they used for???
it will be kind enough if anyone helps me in this regards..
regards
vishal jain.

解决方案

vishal wrote:

I am new to sql and require some help on cursors?
what are they and how and why are they used for???
it will be kind enough if anyone helps me in this regards..
regards
vishal jain.



Cursors are data structures that allow you to manipulate the results of
a query one row at a time. Typically we only do that in client
application code not in SQL. That''s because it is usually much faster,
easier, more concise and more maintainable to use "set based" SQL code
- code that manipulates entire sets of data rather than one row at a
time.

If you are new to SQL then my advice is that you ignore cursors until
you get a lot more expert with set based SQL code. Although there are
certainly legitimate uses for them, cursors are too often badly misused
by the inexperienced who don''t know any better. Only when you have lots
and lots of experience in "real" SQL will you have the sense to
recognise when a cursor is an appropriate solution.

That may not sound like a very helpful answer but if you consider that
probably at least 99% of what the average SQL developer does can be
done without a cursor you will realise that there are lots more
important things to learn first.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--


interesting take on cursors.
I have never used cursors in client code. seemed pretty inefficient to
pass all that crud across the net, and leave the cursor open until the
clients cpu can process it.

i''ve used cursors extensively in stored procedures.

The cursor is the last resort. Whenever possible use set based
solutions. But if you have to process each record step by step,
sometimes it is the only way.


Doug wrote:

interesting take on cursors.
I have never used cursors in client code. seemed pretty inefficient to
pass all that crud across the net, and leave the cursor open until the
clients cpu can process it.

That''s true. Usually most processing should happen at the server. I
didn''t mean to imply otherwise. A client recordset is a cursor of sorts
and that''s what I was referring to.
i''ve used cursors extensively in stored procedures.



Really? For most production tasks I''d say that more than 99% of data
manipulation can best be done without a cursor. Certainly if you make
"extensive" use of cursors then I''d suggest you should be looking
harder for better solutions. That''s unless you are writing lots of
metadata management or admin processes. For example I think I''ve
written maybe 3 or 4 cursors in the last 6 years and all were for
DBA-type tasks.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--


这篇关于什么是sql中的游标???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆