2015-10-01 57 views
0

當我插入多行到我的SQL Server 2008數據庫表中列示:單個INSERT INTO語句中允許有多少個值?

INSERT INTO MyTable (Name, ID) 
VALUES ('First',1), 
('Second',2), 
('Third',3), 
('Fourth',4), 
('Fifth',5) 

如何將這些價值觀的許多我會允許在單一INSERT INTO語句中使用?

+0

我會說999 – lad2025

+0

@ lad2025:你有什麼參考嗎? – c00000fd

回答

5

根據我的測試,限制是1000行。只是試圖插入多行,並想出了這個錯誤:

The number of row value expressions in the INSERT statement exceeds the maximum allowed number of 1000 row values.

它實際上是記錄here

The maximum number of rows that can be inserted in a single INSERT statement is 1000.

而且here

The maximum number of rows that can be constructed by inserting rows directly in the VALUES list is 1000. Error 10738 is returned if the number of rows exceeds 1000 in that case.

注意的是,1000行限制爲僅對於單個VALUES子句。正如評論說Lasse V. Karlsen

It is not the INSERT statement that has a limit, it is the VALUES clause. This is important if you do an insert that pulls data from somewhere. That insert is only limited by memory/transaction space/disk space.

+0

謝謝。好找!我不知道它是如此之低...... – c00000fd

+0

@ lad2025,顯然不是。只是在我的機器上試了一下,能夠插入2k行。 –

+0

因此,對於'UNION ALL',您的最大批量大小爲65,536 * Network Packet Size。 – lad2025

1

"The maximum number of rows in one VALUES clause is 1000"

這不是INSERT語句被限制爲1000行。 Reference

編輯:

創建csv文件(或定義字段分隔符和行分隔符某些文件),並使用BULK INSERT選項加載文件數據庫。文件可以有100000行;使用批量上傳加載大文件不會有任何問題。 Source