创建学生表:
create table student(
stuid int identity(1001,1),
stuname char(10),
stuclass char(15)
)
插入数据:
insert into student values('tracy','计算机0903班')
insert into student values('kobe','计算机0902班')
insert into student values('lucy','计算机0901班')
insert into student values('lily','软件0903班')
insert into student values('tom','网络0903班')
select *from student创建存储过程用于删除student表中的第n行数据:create proc del_rows @n int
as
begin
 declare pp cursor local for select *from student
 declare @i int
 open pp
 set @i=1
 while @i<@n
  begin 
   fetch next from pp
   set @i=@i+1
  end
 delete student where current of pp
 close pp
 deallocate pp
end   小弟对于其中是怎么实现删除第n行的有点不理解。求高人在语句后面给我添加一下注释

解决方案 »

  1.   

    [code=SQL]create proc del_rows @n int
    as
    begin
     declare pp cursor local for select * from student
     declare @i int
     open pp 
     set @i=1 --初始值为1   
     while @i<@n --判断是否小于N 满足条件接着运行
      begin  
      fetch next from pp --扫描下一个
      set @i=@i+1  --@I递增1
      end
     delete student where current of pp  --当不满足@i<@n的条件的时候删除这行数据
     close pp   --关闭游标
     deallocate pp  --删除游标
    end   [/code]
      

  2.   

    while @i<@n
       begin  
      fetch next from pp
       set @i=@i+1
       end
     能不能把这几句给我解释一下?