Monday, January 9, 2017

Insert 1M Records by SQL Server

declare @id int
declare @accountID bigint
declare @IP varchar(20)
select @id = 1
while @id <= 1000000
begin

//Insert 1st Table
INSERT INTO tblE2Account values('TestAccount' + CAST(@id AS VARCHAR(10)) , 'TestName',14,1,'E2TestBY',GETDATE(),'E2TestBY',GETDate(), NULL,0,0,'63,119','10.101.1.115',2)

// Take ID 
Select @accountID = Max(E2AccountId) From tblE2Account where CreatedBy='E2TestBY'
   
// Take ID and put in next Insert
INSERT INTO tblE2IP values('999.9.9.'+ CAST(@id AS VARCHAR(10)) , '23.1167,113.25','No Hostname','Kuala Lumpur','Kuala Lumpur','MY','59200','AS38199 Macro Lynx Sdn Bhd, Internet Service Provider, Malaysia',1,1,'E2TestBY',GETDATE(),NULL,NULL)

Select @IP = '999.9.9.' + CAST(@id AS VARCHAR(10))

INSERT INTO tblE2Transaction values(@IP, null, 2,14,@accountID,1,'1010017387,20.00,0','E2TestBY',GETDATE(),NULL,NULL)

select @id = @id + 1


end


//Avarage 30k records int 20 mins

No comments:

Post a Comment