• Hans Lindgren (10/22/2015)


    In SQL Server 2014 (maybe also in earlier versions) SWITCHing unpartitioned tables is easy.

    Example:

    (Summary: SWITCHing between T1 and T2)

    --Table/Index creation

    CREATE TABLE [dbo].[T1] ( [A] [INT] PRIMARY KEY);

    CREATE TABLE [dbo].[T2] ( [A] [INT] PRIMARY KEY);

    GO

    -- Populate some example table data

    DECLARE @val INT = 1;

    WHILE @val < 100

    BEGIN

    INSERT INTO dbo.T1(A) VALUES (@val);

    SELECT @val=@val+1;

    END;

    Perfect for a some cases! 🙂

    Where's the "switch" part of that code? Did you accidently delete it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)