問(wèn)題描述
好的,我知道它可以做到,我經(jīng)常這樣做,但是為什么在 T-SQL 中做一個(gè)循環(huán)如此困難?我可以想到很多原因,我想通過(guò)查詢結(jié)果集進(jìn)行解析,并做一些沒(méi)有循環(huán)就無(wú)法完成的事情,但設(shè)置和執(zhí)行我的循環(huán)的代碼超過(guò) 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.
我相信其他人也有類似的看法,那么為什么我們?nèi)匀粵](méi)有一種簡(jiǎn)單的方法來(lái)執(zhí)行循環(huán)?
I'm sure others have a similar opinions so why are we still without a simple way to perform a loop?
順便說(shuō)一句:我們終于在 SQL2008 中獲得了 UPSERT(又名 MERGE),所以也許沒(méi)有失去希望.
An aside: we finally got an UPSERT (aka MERGE) in SQL2008 so maybe all hope isn't lost.
推薦答案
SQL 是基于集合的,聲明性語(yǔ)言;不是程序或命令式語(yǔ)言.T-SQL 試圖跨越這兩者,但它仍然建立在一個(gè)基本的基于集合的范式上.
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.
這篇關(guān)于為什么在 T-SQL 中做一個(gè)循環(huán)如此困難的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!