SQL Server Performance

Stored Procedure to delete the records in batch wise

Discussion in 'ALL SQL SERVER QUESTIONS' started by rahulm_32003, Sep 5, 2012.

  1. rahulm_32003 New Member

    Hi All

    I have bunch of tables contains huge number records. All the tables are referring a primary key of table T1.Now.I have to write a stored procedure to delete the records in batches.I am new to SQL server programming .Please help me in writing this stored procedure

    Scenario:

    T1---primary key x1
    T2- referential x1
    T3-referential x1
    T4-referential x1

    Best Regards
  2. FrankKalis Moderator

    Welcome to the forum!
    Something similar to this should get you started:

    SELECT "Starting to delete"
    WHILE @@ROWCOUNT > 0
    BEGIN
    DELETE TOP (x number of rows)
    FROM ...
    WHERE...
    END

Share This Page