快速删除表中前几行的方法(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
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 2008删除或压缩数据库日志的方法
- sql Server 2008 R2还原或删除数据库时总是出错的解决方法
- sql server 2008 快速批量删除表
- SQL Server 2008 无法删除用户的解决方法
- SQL Server 2008 R2 中不能删除复制(replication) 的解决方法
- SQL SERVER 2008无法删除作业的解决方法
- SQL Server 2008删除或压缩数据库日志的方法
- SQL Server 2008删除或压缩数据库日志的方法
- SQL Server 2008 R2:快速清除日志文件的方法
- sql server快速删除记录方法
- SQL Server 2008 R2:快速清除日志文件的方法
- SQL Server 2008删除或压缩数据库日志的方法
- SQL Server 2008 R2:快速清除日志文件的方法
- SQL Server 2008中删除errorlog文件的方法
- SQL Server 2008 R2 中不能删除复制(replication) 的解决方法
- SQL Server 2008删除或压缩数据库日志的方法
- MySQL实现快速删除所有表而不删除数据库的方法
- Linux下使用rsync最快速删除海量文件的方法
- sql server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表 的解决办法
- SQL SERVER 2008中使用VARBINARY(MAX)进行图像存取的实现方法