create table dbo.FinanceMonth
(MonthNum int ,
quantity int
)
;with cte as
(
select 1 as MonthNum,100 as quantity
union all
select MonthNum+1,quantity+100
from cte
where MonthNum<12
)
insert into dbo.FinanceMonth
select *
from cte
2,使用 SET ROWCOUNT 限制返回的行数,但是MS不推荐使用这种方式,“在 SQL Server 的将来版本中,使用 SET ROWCOUNT 将不会影响 DELETE、INSERT 和 UPDATE 语句”。
SET ROWCOUNT 2
select *
from dbo.FinanceMonth
--等价于
select top 2 *
from dbo.FinanceMonth
delete top (2)
from dbo.FinanceMonth
update top(2) dbo.FinanceMonth
set quantity=1
insert top(2) into dbo.FinanceMonth
select * from dbo.FinanceMonth