如何删除满足条件的前N条记录

Nintendo_hc 2011-10-12 02:39:39
比如满足删除条件的记录有10万条,但我只需要删除其中的前100条(按时间顺序)
请教这个SQL语句应该如何写
...全文
99 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangmf_c 2011-10-12
  • 打赏
  • 举报
回复
delete (top 50)
tablename
where ...
jxjdzwang5555 2011-10-12
  • 打赏
  • 举报
回复
delete (top 50) from 表1 where time <10
geniuswjt 2011-10-12
  • 打赏
  • 举报
回复

--nbdba大哥在坑你,这样
delete top (50)
tablename
where ...
[Quote=引用 7 楼 nintendo_hc 的回复:]
引用 1 楼 nbdba 的回复:
2005+


SQL code

delete (top 50)
tablename
where ...


我这样写的
delete (top 50) 表1 where time <10

提示 '(' 附近有语法错误
[/Quote]
Nintendo_hc 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 nbdba 的回复:]
2005+


SQL code

delete (top 50)
tablename
where ...
[/Quote]

我这样写的
delete (top 50) 表1 where time <10

提示 '(' 附近有语法错误
-晴天 2011-10-12
  • 打赏
  • 举报
回复
delete from tb where 条件 and 时间 in(select top 100 时间 from tb where 条件 order by 时间)
--小F-- 2011-10-12
  • 打赏
  • 举报
回复
;with f as
(
select id=row_number()over(order by 时间字段),* from tb
)
delete from f where id<=100
中国风 2011-10-12
  • 打赏
  • 举报
回复
判斷是否有10W條,再刪除
中国风 2011-10-12
  • 打赏
  • 举报
回复
IF (SELECT COUNT(*) FROM table1)>=100000
BEGIN
SET ROWCOUNT 100
DELETE table1
SET ROWCOUNT 0
END
jalor_6 2011-10-12
  • 打赏
  • 举报
回复
顶一顶,更健康
NBDBA 2011-10-12
  • 打赏
  • 举报
回复
2005+

delete (top 50)
tablename
where ...

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧