若是採用insert into 循環一條一條插入速度比較慢spa
能夠先將數據插入臨時表,而後在臨時表數據量到達批量插入的行數時執行例如:目標表 (col1,col2,col3)code
SELECT col1,col2,col3 into #temp FROM 目標表 WHERE 1=2 --根據目標表結構複製一個臨時表 declare @n int set @n=1 while @n<=100000000 begin insert #temp(col1,col2,col3) values ( NEWID(), '48'+right( '00000000'+cast(@n as nvarchar(10)),8), CAST(ABS(CHECKSUM(newID()))%CAST( cast('2003-10-01' as datetime)-cast('1968-03-02' as datetime) AS BIGINT)+CAST(cast ('1968-03-02' as datetime) AS BIGINT) AS DATETIME)+RAND() --隨機時間 ) if @n%100001=100000 --每10萬條記錄執行一次批量插入,能夠自定義 begin insert 目標表(col1,col2,col3) select * from #temp truncate table #temp end set @n=@n+1 end --drop table #temp