問題描述
無法正確表達(dá)問題,因此無法搜索我想要的內(nèi)容.我所需要的只是一個(gè)帶有一列say guids的虛擬表,我將它用于其他目的.沒有實(shí)際編寫相同的 insert .. newID()
n 次,想知道是否有一個(gè)優(yōu)雅的解決方案.
Not able to word the question properly, so couldn't search what I want. All I need is a dummy table with a single column of say guids, which I use it for some other purposes. Without actually writing same insert .. newID()
n times, wondering if there is an elegant solution.
類似的問題是如何用一個(gè) int 列填充一個(gè)空白表,比如 1-n 個(gè)數(shù)字.
Similar question would be how do I populate a blank table with a int column with say 1-n numbers.
Row1: 1
Row2: 2
.......
Row100:100
推薦答案
這種方法非常快.如果您需要從無到有生成數(shù)字表,這可能是可用的最佳"方法.
This method is blisteringly fast. If you need to generate a numbers table from nothing, it's probably the "best" means available.
WITH
t0(i) AS (SELECT 0 UNION ALL SELECT 0),
t1(i) AS (SELECT 0 FROM t0 a, t0 b),
t2(i) AS (SELECT 0 FROM t1 a, t1 b),
t3(i) AS (SELECT 0 FROM t2 a, t2 b),
n(i) AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) FROM t3)
SELECT i FROM n WHERE i BETWEEN 1 AND 100
這篇關(guān)于在表中生成固定數(shù)量的行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!