34,590
社区成员
发帖
与我相关
我的任务
分享
--RT,我知道可以delete top (10) * from tb,但是这个top是根据什么排序的呢?
delete top (10) * from tb order by col desc
--加上order by果断报错了,这个2005新加的delete top用法到底神马情况呢
delete top(10) from table output deleted.*
--看看吧
-- 这样当然可以
delete from tb where col in (select top(10) col from tb order by col desc )
create table tb(id int)
insert into tb select 1 union all select 2 union all select 3 union all select 4 union all select 5
go
delete top (3) from tb
go
select * from tb
go
drop table tb
/*
id
-----------
4
5
(2 行受影响)
*/
declare @T table (col int)
insert into @T
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10
delete top (5) from @T
select * from @t
/*
col
-----------
6
7
8
9
10
*/