Search code examples
sqlsql-serverlarge-data

SQL - Delete table with 372 million rows starting from first row


I have a table with 372 million rows, I want to delete old rows starting from the first ones without blocking the DB. How can I reach that?

The table have

id | memberid | type |      timeStamp          | message |
1     123        10    2014-03-26 13:17:02.000    text

UPDATE:

I deleted about 30 GB of Space in DB, but my DISC is ON 6gb space yet.. Any suggestion to get that free space?

Thank you in advance!


Solution

  • select 1;
    while(@@ROWCOUNT > 0)
    begin
       WAITFOR DELAY '00:00:10';
       delete top(10) from tab  where <your-condition>;
    
    end
    

    delete in chunks using above sql