我想让我的数据库里只保存最新的十条记录,超过十条,删除最旧的一条

2025-04-24 19:54:53
推荐回答(3个)
回答1:

写个触发器吧。在每次插入记录的时候触发,用count(*)判断是否等于10.大于10的话就按id删除最后那条记录就可以了

回答2:

只是显示保持10行
Select top 10 * from ta where a=e // sql server
select * from ta where a=e and rownum=10 // oracle

delete ta where 1=1
and a=e
and d not in (select top 10 id from ta where a=e order by 时间 desc)

回答3:

select top 10 * from bbb