This looks like SQL Server syntax. In that database, I would suggest an updatable CTE:
WITH todelete AS (
SELECT wb.*,
ROW_NUMBER() OVER (ORDER BY Start_TM DESC) as seqnum
FROM WHRW_BATCH wb
)
DELETE FROM todelete
WHERE seqnum > 10000;
This will keep the 10,000 most recent records.
If the table is quite large (i.e. most records are being deleted), then you might find a temporary table is faster:
select top (10000) wb.*
into temp_whrw_batch
from WHRW_BATCH wb
order by Start_TM desc;
Then remove all rows from the table and re-insert:
truncate table WHRW_BATCH;
insert into WHRW_BATCH
select *
from temp_whrw_batch;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…