字段的取值只有两个值“0”“1”,如何快速自动随机产生和录入N个(100百万以上)的数据呢?求教。
请注意“随机”。
我用下列语句产生的是整齐排列的0和1组合。
===
create table ta(id int)--创表
--一次插入100随机的0/1
declare @i int,@j int
select @i=1,@j=100
while @i!>@j
begin
insert ta
select top 1 id from (select 0 as id union all
select 1)as a order by  newid()
select @i=@i+1
end
==

解决方案 »

  1.   

    看個類似的
    http://blog.csdn.net/zjcxc/archive/2006/08/20/1099215.aspx
      

  2.   

    create table ta(id int)--创表
    declare @i int,@j int,@k int
    select @i=1,@j=20
    while @i!>@j
    begin
        select @k = CAST(RAND()*10000 as int)%2 
        insert ta(id) values(@k)
        select @i=@i+1
    endselect * from tadrop table taid          
    ----------- 
    1
    0
    1
    1
    0
    1
    0
    1
    0
    0
    1
    0
    1
    1
    0
    0
    1
    0
    0
    0(所影响的行数为 20 行)
      

  3.   

    用这个:round(rand(checksum(newid())),0)
      

  4.   

    create table ta(id int)--创表
    --一次插入100随机的0/1
    declare @i int,@j int
    select @i=1,@j=100
    while @i!>@j
    begin
    insert ta
    select round(rand(checksum(newid())),0)
    select @i=@i+1
    end