sqlserver学习记录(2014/4/10)

1.执行insert或者delete语句,得到返回的id/name/age,返回结果集

insert into test(id,name,age) output inserted.Name values(3,'test3',16)

2.分页语句

SELECT *FROM
(SELECT TOP 10 * FROM dbo.Area WHERE ar_id NOT IN (SELECT TOP 10 ar_id FROM dbo.Area) ORDER BY dbo.Area.ar_id ASC)
AS t ORDER BY t.ar_id DESC
SELECT *FROM
(SELECT *,ROW_NUMBER() OVER(ORDER BY ar_id) AS nrows FROM dbo.Area) AS t
WHERE t.nrows BETWEEN 11 AND 20

3.存储过程

declare @i int = 1
declare @sum int = 0

while(@i<101)
begin
  if(@i%2=1)
  begin
set @sum = @sum + @i
  end
set @i=@i+1
end

print @sum

 

posted on 2014-05-17 00:43  IOTer  阅读(208)  评论(0编辑  收藏  举报

导航