create table TT(ID numeric(10),name char(20),Englist numeric(5,2),physics numeric(5,2));
go
alter proc tpro
as
begin tran 
 insert into TT(ID,name,Englist,physics) values(3,'张三',89,98);
commit tran
gogo
begin tran 
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
end;
commit tran
goselect COUNT(*) from TT;--我的天啦,8分钟还没有完,我只有中止执了....也不知要多久..
--大家有没有更快的办法

解决方案 »

  1.   


    while @II<10000
    begin
    exec tpro;
    set @II = @II + 1
    end;
      

  2.   

    begin tran 
    declare @II int;
    set @II=1;
    while @II<10000
    begin
    exec tpro;
    --add
    set @II=@II+1;
    end;
    commit tran
      

  3.   

    go
    begin tran  --如何事务,不用事务会很慢
    declare @II int;
    set @II=1;
    while @II<10000
    begin
    exec tpro;
     set @II=@II+1;--弄丢了,执行是有的
    end;
    commit tran
    go
      

  4.   

    begin tran 
     insert into TT(ID,name,Englist,physics) values(3,'张三',89,98);
    commit tran
    这里是begin tran和commit tran是多余的IF @@TRANCOUNT > 0 COMMIT TRAN执行几次把没有提交的事务提交上去set nocount on
    begin tran 
    declare @II int;
    set @II=1;
    while @II<10000
    begin
    exec tpro;
    end;
    commit tran
    set nocount off这样也会快一倍多
      

  5.   

    set nocount on
    begin tran 
    declare @II int;
    set @II=1;
    while @II<10000
    begin
    exec tpro;
    set @II=@II+1
    end;
    commit tran
    set nocount off