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 中做一个循环如此困难
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
