如果是插入记录,可以不用循环insert into t(字段1,字段2) 
select 0,1
union all
select 1,2
.....

解决方案 »

  1.   

    循环
    while 条件
    begin
    语句
    end
      

  2.   

    就是想插入很多数值,怎么用sql语句循环插入
      

  3.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[temp3]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[temp3]create table temp3(字段1 int not null ,字段2 int not null)
    godeclare @i int,@j int
    select @i=0
    while @i<=9
      begin
         set @j=0     while @j<=9
           begin
               insert into temp3 select @i,@j
              set @j=@j+1
           end
       
       set @i=@i+1
    end
    select * from temp3
    /*
    字段1    字段2
    0 0
    0 1
    0 2
    0 3
    0 4
    0 5
    0 6
    0 7
    0 8
    0 9
    1 0
    1 1
    1 2
    1 3
    1 4
    1 5
    1 6
    1 7
    1 8
    1 9
    2 0
    2 1
    2 2
    2 3
    2 4
    2 5
    2 6
    2 7
    2 8
    2 9
    3 0
    3 1
    3 2
    3 3
    3 4
    3 5
    3 6
    3 7
    3 8
    3 9
    4 0
    4 1
    4 2
    4 3
    4 4
    4 5
    4 6
    4 7
    4 8
    4 9
    5 0
    5 1
    5 2
    5 3
    5 4
    5 5
    5 6
    5 7
    5 8
    5 9
    6 0
    6 1
    6 2
    6 3
    6 4
    6 5
    6 6
    6 7
    6 8
    6 9
    7 0
    7 1
    7 2
    7 3
    7 4
    7 5
    7 6
    7 7
    7 8
    7 9
    8 0
    8 1
    8 2
    8 3
    8 4
    8 5
    8 6
    8 7
    8 8
    8 9
    9 0
    9 1
    9 2
    9 3
    9 4
    9 5
    9 6
    9 7
    9 8
    9 9*/
      

  4.   

    這種只能夠循环插入declare @i int,@j int
    select @i=0,@j=0while @i<=9
    begin
      while @j<=9
      begin
        insert into tb(col1,col2) values(@i,@j)
        set @j=@j+1
      end
    set @i=@i+1
    end大體上是這樣的﹐其他自己補充