以下的代码为什么没有实现我想要的结果,100的倍数时提交一次set implicit_transaction on;drop table angusTest_tbl;--删除表
--创建表
create table angusTest_tbl(
 id int primary key,--用来记录行数
 now datetime  --时间
);
--删除存储过程
drop procedure angusTest_proc
--建立存储过程
create procedure angusTest_proc
as
begin
    declare @v_timenow datetime
declare @i int
    set @i=1
   
 while 2>0
   begin
       select @v_timenow=getDate() --得到当前时间
       insert into angusTest_tbl(id,now) values(@i,@v_timenow);  
if @i%100=0   --i是100的倍数时,提交一次
     begin
       commit    
     end
   WAITFOR DELAY '00:00:02'   --每一次循环,停2秒
   set @i=@i+1;  --自增
  end
end
--执行存储过程
begin
 exec angusTest_proc
end
--查找表内容
select * from angusTest_tbl;

解决方案 »

  1.   

    while 2>0恒成立 楼主你想做什么
      

  2.   

    自己结帖
    答案是
    use demo;
    SET IMPLICIT_TRANSACTIONS off;
    drop table angusTest_tbl;--删除表
    --删除存储过程
    drop procedure angusTest_proc
    --创建表
    create table angusTest_tbl(
     id int primary key,--用来记录行数
     now datetime  --时间
    );
    --建立存储过程
    create procedure angusTest_proc
    as
    begin
        declare @v_timenow datetime
    declare @i int
        set @i=1
         begin transaction
     while 2>0
       begin
           select @v_timenow=getDate() --得到当前时间
           insert into angusTest_tbl(id,now) values(@i,@v_timenow);  
    if @i%100=0   --i是100的倍数时,提交一次
         begin
          commit transaction;
          begin transaction;  
         end 
       --WAITFOR DELAY '00:00:01'   --每一次循环,停2秒
       set @i=@i+1;  --自增
      end
    end--执行存储过程
    begin
     exec angusTest_proc
    end
    --查找表内容
    select * from angusTest_tbl;
    select count(*) from angusTest_tbl;
      

  3.   

    begin tran
    @count=0
    while(@count<100)
      insert
      @count++
    commit