码迷,mamicode.com
首页 > 数据库 > 详细

T-SQL Recipes之删除重复行

时间:2016-05-17 19:15:01      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

一、准备基础数据

(1)创建辅助表,方便以后倾向于Set-base方式解决问题

技术分享
-- 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之删除重复行

标签:

原文地址:http://www.cnblogs.com/cdjboy/p/5502503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!