SQL SERVER 2008的top增強

weixin_34377065發表於2012-11-11

create table testTop

(
 value int primary key
)

--可以一次插入頂部的多條記錄

insert top(5) into testTop 
select *
from (select 1 as value union select 2 union select 3 union select 4
   union select 5 union select 6 union select 7) as sevenRows
go 

 

select * from testTop

update top(2) testTop

set value=value * 100 delete top(3) testTop

 

--可以動態設定top的引數

declare @rowsToReturn int
select  @rowsToReturn=10
select Top(@rowsToReturn) *
from HumanResources.Employee

相關文章