Re: Inserting Multiple Rows
From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 08/24/04
- Next message: Anith Sen: "Re: How to split rows to columns?"
- Previous message: Tibor Karaszi: "Re: Help with unique fields"
- In reply to: Arsen V.: "Inserting Multiple Rows"
- Next in thread: Narayana Vyas Kondreddi: "Re: Inserting Multiple Rows"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Aug 2004 21:54:38 +0200
Arsen,
Here's a reply I just posted in -programming in the same topic:
In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. In case Jon wants
to stick with INSERT
statements:
1. Group several INSERT in the same transaction. Each transaction requires an I/O (write to the transaction
log). You can cut time, perhaps to some 10% by doing several in the same transaction. Not too many, though.
Start with about 1k - 5k and test from there.
2. Group several INSERT in the same batch. Each batch requires a network roundtrip, parsing etc. By batch, I
mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server
(each ExecuteNonQuery is a batch, for instance).
-- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ "Arsen V." <arsen@community.nospam> wrote in message news:%23RPgXNhiEHA.3172@tk2msftngp13.phx.gbl... > Hello, > > What is the optimal way to insert multiple rows (around 1000) from a web > application into a table? > > The user enters multiple lines into a text box (up to 10,000). The ASP.NET > application breaks that data into a string array. Each line is an item of > that array. > > The user clicks Submit. > > I want to insert all those lines into a table in SQL Server. > > I know that with MySQL 4.00 and newer, I can simply issue the following > command: > > INSERT INTO Table1 (field1) VALUES ('apple'), ('pear'), ('soda'), ('drink') > > This will very quickly insert all those values into Table1.field1. > > I know that in SQL Server, I can use a BULK INSERT from a file or BCP. > However, I need to do the insert from a web application. > > It is better to create one large SqlCommand with all the insert statements: > > INSERT Table1 (field1) VALUES ('apple'); > INSERT Table1 (field1) VALUES ('pear'); > INSERT Table1 (field1) VALUES ('fruit'); > INSERT Table1 (field1) VALUES ('drink'); > > and execute it in one shot. > > Or is it better to execute each insert separatly. > > Thanks, > Arsen > >
- Next message: Anith Sen: "Re: How to split rows to columns?"
- Previous message: Tibor Karaszi: "Re: Help with unique fields"
- In reply to: Arsen V.: "Inserting Multiple Rows"
- Next in thread: Narayana Vyas Kondreddi: "Re: Inserting Multiple Rows"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|