WorkaHolic/MSSQL

MSSQL 500만건 랜덤 데이타 생성하기

2010. 4. 8. 23:41
반응형

1. 500만건 데이타 만들기

 

-- 테이블 생성

CREATE TABLE random_data
(
col1    int      PRIMARY KEY IDENTITY(10,10) NOT NULL,
col2    int      NOT NULL DEFAULT CASE
                 -- Random integer between -9999 and +9999
                 WHEN CONVERT(int, RAND() * 1000) % 2 = 1
                 THEN (CONVERT(int, RAND() * 100000) % 10000 * -1 )
                 ELSE CONVERT(int, RAND() * 100000) % 10000
                 END,
col3    char(15) NOT NULL DEFAULT
                 CHAR((CONVERT(int, RAND() * 1000) % 26 ) + 65)
                 -- 65 is 'A'
                 + CHAR((CONVERT(int, RAND() * 1000) % 26 ) + 65)
                 + CHAR((CONVERT(int, RAND() * 1000) % 26 ) + 65)
                 + CHAR((CONVERT(int, RAND() * 1000) % 26 ) + 65)
                 + REPLICATE(CHAR((CONVERT(int, RAND() * 1000)
                     % 26) + 65), 11)
)
GO

-- Insert

DECLARE @counter int
SET @counter=1
WHILE (@counter <= 5000000)
    BEGIN
    INSERT random_data DEFAULT VALUES
    SET @counter=@counter + 1
    END

 

 

500만건 입력 하는데 걸리는 시간이 ... 무려 20분 후덜덜... 용량이 150메가나 되는군요..

반응형