RBAR 与基于集合的 SQL 编程
阅读了 RBAR< 上的此链接/a> 和这个,我对 RBAR 的理解相当于:
- 任何有循环和游标
- 任何不基于集合的东西
我知道这听起来有点完全,这就是为什么我问是否有人对基于集合的编程有一个更优雅的解释(在 SQL 上下文中)。
Having read this link on RBAR and this, my understanding of RBAR amounts to this:
- Anything that have loops and cursors
- Anything that's not set based
I know this sounds kinda wholly which is why I am asking if anyone has a more elegant explanation as to what set-based programming is (within SQL context).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于集合的编程基于集合的数学概念,并且具有一次对整个集合起作用的运算符。过程式(RBAR)编程更多地基于文件和记录的传统计算机概念。因此,要将 X 部门所有员工的工资增加 10%:
基于集合:
过程式(极端示例,伪代码):
在过程式版本中,一次仅更新一个员工行;在基于集合的版本中,“部门 X 的员工集合”中的所有行都会立即更新(就我们而言)。
不确定这是否会为您在链接中已经阅读的内容添加任何内容,但我想我会尝试一下!
Set-based programming is based upon the mathematical concept of a set, and has operators that work on a whole set at a time. Procedural (RBAR) programming is based more on the traditional computer concepts of files and records. So to increase the salary of all employees in department X by 10%:
Set-based:
Procedural (extreme example, pseudo-code):
In the procedural version, only one employee row is being updated at a time; in the set-based version, all rows in the "set of employees in department X" are updated at once (as far as we are concerned).
Not sure this adds anything to what you will have already read in your links, but I thought I'd have a shot at it!
我将指出基于集合的处理可能涉及循环。如果您想批量处理而不是在一个基于集合的进程中将一百万条记录加载到其中时绑定多个表,您可以循环处理批量记录,这比一次操作一行的游标更快,并且对于您的数据库来说,这可能比执行一个巨大的插入语句要好得多。
一些 RBAR 进程看起来也不像游标或循环。这些将包括相关子查询和许多用户定义的函数。
I will point out that set-based processing can involve loops. If you want to process in batches rather than tie up several tables while you load a million records into them in one set-based process, you can loop through batches of records, this is faster than a cursor which operates one row at a time and may be far better for your database than doing one giant insert statement.
Some RBAR processes don't look like cursors or loops either. These would include correlated subqueries and many user-defined functions.