---快速删除表中前几行的方法(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
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