T-SQL Recipes之删除重复行
时间:2021-07-01 10:21:17
帮助过:2人阅读
Creating and Populating the Nums Auxiliary Table
SET NOCOUNT
ON;
IF OBJECT_ID(
‘dbo.Nums‘,
‘U‘)
IS NOT NULL
DROP TABLE dbo.Nums;
CREATE TABLE dbo.Nums(n
INT NOT NULL PRIMARY KEY);
DECLARE @max AS INT ,
@rc AS INT;
SET @max = 1000000;
SET @rc = 1;
INSERT INTO dbo.Nums
( n )
VALUES (
1 );
WHILE @rc * 2 <= @max
BEGIN
INSERT INTO dbo.Nums
( n )
SELECT n
+ @rc
FROM dbo.Nums;
SET @rc = @rc * 2;
END
INSERT INTO dbo.Nums
( n
)
SELECT n
+ @rc
FROM dbo.Nums
WHERE n
+ @rc <= @max;
GO
View Code
T-SQL Recipes之删除重复行
标签: