如果有主键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
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
truncate table tablename
insert into tablename select * from #temp
drop table #temp
......
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.主鍵字段
......
......