为什么在 T-SQL 中做一个循环如此困难

时间:2022-11-08
本文介绍了为什么在 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 中做一个循环如此困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:是否可以在使用 sql 的更新语句中使用 MAX? 下一篇:更改表以根据 Order By 添加 Identity 列

相关文章

最新文章