• Lokesh Vij (9/19/2012)


    There is a requirement, details as below:

    1) Copy data from transaction table (around million records inserted daily) into a archival table

    2) Delete data from transaction table

    3) Step (1) - transactions can be minimally logged

    4) Step (2) - all transactions completely logged.

    5) There are 14 transaction tables; step (1) to (4) needs to be repeated for all transaction tables.

    Here is the sample code (for one table)

    -- assuming archival table already exists

    -- Step 1: Copy data into archivalTbl from transactionTbl with minimal logging

    INSERT INTO archivalTbl WITH (TABLOCK)

    (col1,

    col2,

    col3)

    SELECT col1,

    col2,

    col3

    FROM transactionTbl;

    -- Step 2: Delete data from transactionTbl will full logging

    DELETE FROM transactionTbl;

    Can someone please advise any best way to achieve this?

    Thank you.

    First, INSERT INTO will be fully logged, not minimally logged (iirc).

    So, let me get this straight, each table that needs to have records archived adds approximately 1,000,000 records each daily. Are you archiving that many records daily as well? What we really need to know is the structure of the data (DDL for the tables) so that we can make a determination of needs. If you are adding and deleting nearly 2,000,000 rows of data, then partitioning may be the what is needed for the archiving process. Depending on the data, it may be possible to establish a slinding window scenerio for quickly archiving data. This could also be done for adding data depending on how new records are added. If it is by a bulk process, a similar process can be used to quickly add the data as well.