快速删除表中前几行的方法(sql server 2008)

---快速删除表中前几行的方法(sql server 2008)
if object_id('tb') is not null drop table tb
go
create table tb (id int)
go
insert tb select 4
union all select 1
union all select 3
go
--使用聚集索引
create index idx1 on tb(id)
go
set rowcount 2
delete tb from tb with(index = idx1)
set rowcount 0
go


--使用子查询
delete tb where id in (select top (1) id from tb order by id)
go
delete tb from (select top (1) * from tb order by id)tb
--使用cte
;with a as
(select top (1) * from tb order by id)
delete a
go


select * from tb
go


drop table tb
go
阅读更多
个人分类: sql server
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭