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 中做一个循环如此困难


基础教程推荐
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01