您的位置:首页 > 数据库

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

2011-10-13 11:36 239 查看
---快速删除表中前几行的方法(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: