一张表tb
字段
f1 是自动增长标识
f2 是CHAR类型
我要做个测试,希望能够循环插入
f1   f2
1    test1
2    test2
3    test3





求这样一个函数或者说是查询语句。

解决方案 »

  1.   

    create table tab(f1 int identity(1,1),f2 varchar(10))declare @i int
    set @i=1
    while @i<101
    begin
    insert into tab select 'test'+cast(@i as varchar(4))
    end
      

  2.   

    http://topic.csdn.net/u/20090604/21/bfcff88a-6089-46be-ae4f-e19ea4fd21ed.html
      

  3.   

    -- =========================================
    -- -----------t_mac 小编-------------
       ---希望有天成为大虾---- 
    -- =========================================IF OBJECT_ID('tb') IS NOT NULL
      DROP TABLE tb
    GO
    CREATE TABLE tb(f1 int identity(1,1) ,f2 varchar(100))
    go
    declare @f2 varchar(100),@n int
    set @n=1
    set @f2='test'
    while @n<100
    begin
    insert tb
    values (@f2+CONVERT(varchar,@n)) 
    set @n=@n+1
    end
    select * from tb
    go
    /*------------
    1 test1
    2 test2
    3 test3
    4 test4
    5 test5
    6 test6
    7 test7
    8 test8
    9 test9
    10 test10
    11 test11
    12 test12
    13 test13
    14 test14
    15 test15
    16 test16
    17 test17
    18 test18
    19 test19
    20 test20
    21 test21
    22 test22
    23 test23
    24 test24
    25 test25
    26 test26
    27 test27
    28 test28
    29 test29
    30 test30
    31 test31
    32 test32
    33 test33
    34 test34
    35 test35
    36 test36
    37 test37
    38 test38
    39 test39
    40 test40
    41 test41
    42 test42
    43 test43
    44 test44
    45 test45
    46 test46
    47 test47
    48 test48
    49 test49
    50 test50
    51 test51
    52 test52
    53 test53
    54 test54
    55 test55
    56 test56
    57 test57
    58 test58
    59 test59
    60 test60
    61 test61
    62 test62
    63 test63
    64 test64
    65 test65
    66 test66
    67 test67
    68 test68
    69 test69
    70 test70
    71 test71
    72 test72
    73 test73
    74 test74
    75 test75
    76 test76
    77 test77
    78 test78
    79 test79
    80 test80
    81 test81
    82 test82
    83 test83
    84 test84
    85 test85
    86 test86
    87 test87
    88 test88
    89 test89
    90 test90
    91 test91
    92 test92
    93 test93
    94 test94
    95 test95
    96 test96
    97 test97
    98 test98
    99 test99
    -------*/