如果有主键ID:
delete tablename where id not in (
select top 2000 id from tablename order by datecol desc
)注意:一般是保存后2000条记录,所以我用了order by datecol desc,
如果你一定要保留前2000条记录,请用order by datecol asc

解决方案 »

  1.   

    insert into #temp select top 2000 * from tablename order by datecol desc 
    truncate table tablename
    insert into tablename select * from #temp
    drop table #temp
      

  2.   

    delete from yourtable where time < (select max(time) from (select top 2000 * from yourtable order by time) x )
      

  3.   

    ......
    ......
    declare @count int
    select @count = count(1) from yourTableName;
    set rowcount @count - 2000
    select 主鍵字段 into #temp1 from yourTableName order by 時間字段
    delete yourTableName from #temp1
    where yourTableName.主鍵字段 = #temp1.主鍵字段
    ......
    ......