SQL SERVER 快速插入千萬條資料
1. 正常插入:插入非常慢。
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 end commit
2.優化插入:插入速度明顯提升。
3.總結:一條語句可插入多條資料,以此來加快插入速度。具體原理,待大神們解釋。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 end commit
相關文章
- 如何快速安全的插入千萬條資料
- php插入千萬條資料庫指令碼PHP資料庫指令碼
- java之5分鐘插入千萬條資料Java
- sql server 2000 一個表的資料插入到三個相關聯表中,一條一條的插入SQLServer
- SQL Server快速匯入資料分享SQLServer
- 資料千萬條,安全第一條
- 怎麼快速插入 100 條資料,用時最短!
- JDBC向sql server插入50萬條資料出現:ava.lang.OutOfMemoryError: Java heap spaceJDBCSQLServerErrorJava
- 千萬條資料,Stack Overflow 是如何實現快速分頁的?
- java poi讀取Excel資料 插入到SQL SERVER資料庫中JavaExcelSQLServer資料庫
- SQL Server 按照條件統計雨量資料SQLServer
- SQL Server大量插入 JavaSQLServerJava
- 【SQL】實現每隔一分鐘插入一條資料SQL
- XML文件插入SQL Server2000資料庫(2)XMLSQLServer資料庫
- XML文件插入SQL Server2000資料庫(1)XMLSQLServer資料庫
- SQL Server 查詢資料庫中所有表資料條數SQLServer資料庫
- SQL Server 2005中插入XML資料的三種方法SQLServerXML
- C#快速入門教程(27)—— SQL Server資料庫C#SQLServer資料庫
- 用一條mysql語句插入多條資料MySql
- SQL Server 多表聯合查詢取最新一條資料SQLServer
- 資料千萬條,備份第一條,資料找不回,老闆兩行淚
- SQL語句批量插入資料SQL
- sqlserver 2005 快速插入資料SQLServer
- SQL Server資料庫恢復,SQL Server資料恢復,SQL Server資料誤刪除恢復工具SQLRescueSQLServer資料庫資料恢復
- SQL Server 2014如何使用遊標迴圈向遠端資料庫插入資料SQLServer資料庫
- SQL Server資料庫安全SQLServer資料庫
- SQL server 修改表資料SQLServer
- SQL Server 資料庫映象SQLServer資料庫
- SQL Server 資料庫索引SQLServer資料庫索引
- 資料庫映象 (SQL Server)資料庫SQLServer
- 高效資料移動指南 | 如何快速實現資料庫 SQL Server 到 Dameng 的資料同步?資料庫SQLServer
- sql 多組條資料取最新的一條資料SQL
- 【SQL Server】--SQL Server資料庫bak檔案還原SQLServer資料庫
- mariadb快速插入100w資料
- MySQL 匯出一條資料的插入語句MySql
- SQL Server伺服器上需要匯入Excel資料的必要條件SQLServer伺服器Excel
- mybatis插入資料、批量插入資料MyBatis
- 批量插入 1 萬條資料,DB 查詢構造器和原生 SQL 效能比較SQL