0
这个方法在做本地测试的时候用的比较多。直接返回指定n行数字。
出处: http://tsql.solidq.com/books/source_code/Performance.txt
Usage:
出处: http://tsql.solidq.com/books/source_code/Performance.txt
CREATE FUNCTION [dbo].[GetNums](@n AS BIGINT) RETURNS TABLE AS RETURN WITH L0 AS(SELECT 1 AS c UNION ALL SELECT 1), L1 AS(SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B), L2 AS(SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B), L3 AS(SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B), L4 AS(SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B), L5 AS(SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B), Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS n FROM L5) SELECT n FROM Nums ORDER BY n OFFSET 0 ROWS FETCH FIRST @n ROWS ONLY; GO
Usage:
INSERT INTO parents SELECT n, n, n FROM [dbo].[GetNums](100000)
Post a Comment