Search code examples
sqloracletestingoracle11gsql-delete

Left 1000 records from delete 11g?


Table is huge. For testing application I want to delete all, except 1000 records from table. 1000 lucky records don't have identifier that can given as:

DELETE FROM HUGE_TABLE t WHERE t.IDENTIFIER!='LUCKY'

What is best way in one sql statement?


Solution

  • count the numberOfRecordsOnYourDB and do:

    set ROWCOUNT  (numberOfRecordsOnYourDB - 1000 )
    delete from hugetable
    Go
    

    This will delete records from your table but stop processing after the specified number of rows.

    oh and don't forget to set the ROWCOUNT back to a big value, or just open a new connection to do the other tasks