querycontenttable表中有queryflag、queryresult字段,均为文本。
我想向querycontenttable表中插入100万条记录,其中queryflag字段为以40数字开头的18位数字,想动态生成,并且不能是连续的数字,或者太有规律的数字,如不能是401000000000000000,401000000000000002,401000000000000004,querysult字段值固定,请问应如何快速生成插入这100万条记录,谢谢。

解决方案 »

  1.   

    不怎么懂SQL,各位能否说下详细的步骤或者SQL语句?谢谢
      

  2.   

    關注……關鍵是快速生成非連續(可否理解為隨機)的100W條數據可否先生成100W條18位的隨機字符串(只能選數字),然后將其寫入Table中做Update
    頂LZ
      

  3.   

    --參考
    --创建视图 
    if object_id('myview')is not null drop view myview
    go
    create view myview as select re=rand() 
    go
    --自定义函数:取得指定范围的随机数 
    if object_id('mydata')is not null drop function mydata
    go
    create function mydata( 
    @a int, 
    @b int) 
    returns decimal(38,0) 
    as 
    begin 
    declare @r decimal(38,0) 
    select @r='40'+right('0000000000000000'+ltrim(cast(re*(@b-@a)+@a as decimal(38,0))),16) from myview 
    return(@r) 
    end 
    go 
    select dbo.mydata(1,99999) from sysobjects
    /*---------------------------------------- 
    400000000000055383
    400000000000067449
    400000000000030553
    400000000000093300
    400000000000023122
    400000000000080209
    400000000000041881
    400000000000040881
    400000000000005350
    400000000000048242
    400000000000007876
    400000000000003046
    400000000000018935
    400000000000075000
    400000000000051051
    400000000000086513
    400000000000082128
    400000000000077640
    400000000000056481
    400000000000077209
    400000000000083367
    400000000000014251
    400000000000052225
    400000000000033504
    400000000000090696
    400000000000012382
    400000000000035489
    400000000000032963
    400000000000048592
    400000000000092691
    400000000000033574
    400000000000045010
    400000000000037968
    400000000000005150
    400000000000044117
    400000000000080478
    400000000000068615
    400000000000053367
    400000000000082489
    400000000000023543
    400000000000007013
    400000000000048613
    400000000000022425
    400000000000024232
    400000000000045325
    400000000000013243
    400000000000088897
    400000000000039647
    400000000000026280
    400000000000086723
    400000000000094878
    400000000000054752
    400000000000037610
    400000000000019444
    400000000000082694
    400000000000015994
    400000000000090069
    400000000000080006
    400000000000042659
    400000000000049667*/
      

  4.   

    老大的
    如何快速生成100万不重复的8位编号
    http://blog.csdn.net/zjcxc/archive/2006/08/20/1099215.aspx
      

  5.   

    --取得随机数的视图
    CREATE VIEW v_RAND
    AS
    SELECT re=STUFF(RAND(),1,2,'')
    GO--生成随机编号的函数
    CREATE FUNCTION f_RANDBH(@BHLen int)
    RETURNS varchar(50)
    AS
    BEGIN
    DECLARE @r varchar(50)
    IF NOT(ISNULL(@BHLen,0) BETWEEN 1 AND 50)
    SET @BHLen=10lb_bh: --生成随机编号的处理
    SELECT @r=re FROM v_RAND
    WHILE LEN(@r)<@BHLen
    SELECT @r=@r+re FROM v_RAND
    SET @r=LEFT(@r,@BHLen) --检查编号在基础数据表中是否存在
    IF EXISTS(SELECT * FROM tb WITH(XLOCK,PAGLOCK) WHERE BH=@r)
    GOTO lb_bh RETURN(N'4010000000'+@r)
    END
    GO--创建引用生成随机编号的函数
    CREATE TABLE tb(
    BH char(20) PRIMARY KEY DEFAULT dbo.f_RANDBH(10),
    col int)--循环插放数据declare @i int
    set @i=1
    while @i<1000000
    begin 
    BEGIN TRAN
    INSERT tb(col) VALUES(@i)
    set @i=@i+1
    COMMIT TRAN
    endSELECT * FROM tb order by col/*BH                   col         
    -------------------- ----------- 
    40100000009247323659 1
    40100000001846050438 2
    40100000004811528541 3
    40100000005252479485 4
    40100000000982073896 5
    40100000002877694941 6
    40100000008271926675 7
    40100000005128456024 8
    40100000001594723533 9
    40100000001171545417 10
    .
    .
    .
    .
    .
    .
    .
    */
      

  6.   

    select '40'+'10000000000000000'+cast(1000000*rand() as varchar(30))
      

  7.   

    怎么感覺像生成的身份證號碼?
    LZ想做什么啊?declare @temp   table (A varchar(18))
    declare @count as int 
    set @count = 1000
    declare @i as int 
    set @i = 10000
    while @i>0 
    begin
    declare @rand as INT
    declare @param as int 
    set @param = datepart(millisecond,getdate())%100
    if( @param = 0 )
    set @param = 99
    SET @rand = @I + @count
    insert into @temp(A)
     Select '40'+right('0000000000000000' + cast(cast(rand(@i*@param)*100000000 as bigint) as varchar) + cast( cast(rand(@rand%(@param))*100000000 as bigint) as varchar),16) 
    set @i=@i -1 
    if( @i%1000 = 0 )
    print cast(@i as varchar)
    end
    select A from @temp
      

  8.   


    declare @tb table (id decimal(20,2) ,b varchar(10) default('a'))
    declare @i decimal(20,2)
    set @i=1000000;
    while @i>0
    begin
    insert into @tb (id)
    select '40'+ right('00000000000'+ CAST( cast( RAND()*1000000 as int) as varchar(20)),16)
    set @i=@i-1
    end
    select * from @tb