Skip to content

Instantly share code, notes, and snippets.

@jbnv
Last active December 28, 2015 22:46
Show Gist options
  • Save jbnv/59d18bbef99d4bf89f64 to your computer and use it in GitHub Desktop.
Save jbnv/59d18bbef99d4bf89f64 to your computer and use it in GitHub Desktop.
Creates a table containing all integers between 0 and 2^20-1 inclusive. (Platform independent.)
CREATE TABLE Numbers
(
N INT NOT NULL,
CONSTRAINT PK_Numbers
PRIMARY KEY CLUSTERED (N)
WITH FILLFACTOR = 100
)
INSERT INTO Numbers (N)
SELECT ROW_NUMBER() OVER(ORDER BY a.n,b.n,c.n,d.n,e.n,f.n,g.n,h.n,i.n,j.n) AS [N]
FROM ( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) a (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) b (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) c (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) d (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) e (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) f (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) g (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) h (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) i (n),
( SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3) j (n)
@jbnv
Copy link
Author

jbnv commented Dec 28, 2015

Not sure if ROW_NUMBER() OVER() is platform-independent or just SQL Server 2008 and later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment