Why is it so difficult to do a loop in T-SQL(为什么在 T-SQL 中做一个循环如此困难)
问题描述
好的,我知道它可以做到,我经常这样做,但是为什么在 T-SQL 中做一个循环如此困难?我可以想到很多原因,我想通过查询结果集进行解析,并做一些没有循环就无法完成的事情,但设置和执行我的循环的代码超过 20 行.
OK, I know it can be done, I do it quite often, but why so difficult to do a loop in T-SQL? I can think of a ton of reasons I'd want to parse thru a query result set and do something that simply can't be done without a loop, yet the code to setup and execute my loop is > 20 lines.
我相信其他人也有类似的看法,那么为什么我们仍然没有一种简单的方法来执行循环?
I'm sure others have a similar opinions so why are we still without a simple way to perform a loop?
顺便说一句:我们终于在 SQL2008 中获得了 UPSERT(又名 MERGE),所以也许没有失去希望.
An aside: we finally got an UPSERT (aka MERGE) in SQL2008 so maybe all hope isn't lost.
推荐答案
SQL 是基于集合的,声明性语言;不是程序或命令式语言.T-SQL 试图跨越这两者,但它仍然建立在一个基本的基于集合的范式上.
SQL is a set-based, declarative language; not a procedural or imperative language. T-SQL tries to straddle the two, but it's still built on a fundamentally set-based paradigm.
这篇关于为什么在 T-SQL 中做一个循环如此困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么在 T-SQL 中做一个循环如此困难


基础教程推荐
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01