1. 正常插入:插入非常慢。
2.優化插入:插入速度明顯提公升。declare @count int = 10000000, @index int = 0
begin tran
while(@index < @count)
begin
insert into ordertest(id) values
(round(rand() * 10000000, 0))
set @index = @index + 1
endcommit
declare @count int = 10000000, @index int = 0
begin tran
while(@index < @count)
begin
insert into ordertest(id) values
--1
(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--2,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--3,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--4,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--5,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--6,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--7,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--8,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--9,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
--10
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
,(round(rand() * 100000000, 0))
set @index = @index + 100
endcommit
3.總結:一條語句可插入多條資料,以此來加快插入速度。具體原理,待大神們解釋。
Mysql 千萬資料快速匯入
最近碰到個專案,需要 千萬條資料入庫的問題,有原本的 類 csv 檔案匯入,統計了下 資料行大概有 1400w 行之多 二話不說,建表,直接 load load data local infile data data.csv into table pk book price character se...
sql server 插入使用者
建立登陸使用者 use master create login mashenghao with password kline default database kchnetdb default language us english check expiration off,check policy...
PHP 千萬級別資料插入
header content type text html charset utf 8 設定 執行不受時間限制 set time limit 0 鏈結資料庫 con mysqli connect 127.0.0.1 root test if mysqli connect error 設定編碼為utf...