본문 바로가기

Database/MSSQL work

SQL 대량의 데이터 랜덤으로 넣기

대량의 데이터 넣기~~

DECLARE @count INT
SET @count = 1
WHILE(@count <=300)
BEGIN
	INSERT INTO Person
	VALUES
		(
		   CONCAT('aaa',@count),
           CONCAT('aaa',@count),
           CONCAT('홍길동',@count),
           '01012345678',
		   '서울시 서초구',
           CONCAT('aaa', @count, '@aa.co.kr')
		)
	
	INSERT INTO Employee
	VALUES
		(
			FORMAT(CAST(CONCAT(YEAR(GETDATE()),MONTH(GETDATE()), @count) AS INT), 'D10'),			
			@count,
			CAST(8*RAND() + 1 AS INT),
			CAST(5*RAND() + 2 AS INT)
		)
	SET @count = @count +1
END

SET @count = 1
WHILE(@count <=500)
BEGIN
	INSERT INTO Product
	VALUES
		(
			FORMAT(CAST(CONCAT(YEAR(GETDATE()),MONTH(GETDATE()), @count) AS INT), 'D10'),
		    CAST(4*RAND() + 1 AS INT),
			CONCAT('제품', @count),
			CONCAT(YEAR(GETDATE()), MONTH(GETDATE()), DAY(GETDATE()))
		)
	SET @count = @count +1
END
GO