473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Inserting Multiple Rows

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
Nov 18 '05 #1
5 6144
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." <ar***@community.nospam> wrote in message news:%2****************@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

Nov 18 '05 #2
Making a call for each insert would be the slowest option.

In SQL Server, you could insert multiple rows as shown below:

INSERT INTO TableName (Col1, Col2)
SELECT 1, 2
UNION ALL
SELECT 3, 4
UNION ALL
SELECT 5, 6

Also see OPENXML in SQL Server 2000 Books Online.
--
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Arsen V." <ar***@community.nospam> wrote in message
news:%2****************@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

Nov 18 '05 #3
Vyas,

Do you think that a SELECT with UNION will significally outperform several INSERTs in the same batch and
transaction? I never thought about comparing the two...

If it weren't for my girlfriend complaining right now in the living room, I'd do a test right now... :-)

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Narayana Vyas Kondreddi" <an*******@hotmail.com> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...
Making a call for each insert would be the slowest option.

In SQL Server, you could insert multiple rows as shown below:

INSERT INTO TableName (Col1, Col2)
SELECT 1, 2
UNION ALL
SELECT 3, 4
UNION ALL
SELECT 5, 6

Also see OPENXML in SQL Server 2000 Books Online.
--
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Arsen V." <ar***@community.nospam> wrote in message
news:%2****************@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


Nov 18 '05 #4
How important is loading all rows or no rows? Are all 1000 rows one logical
transaction? Is the application fault-tolerant and able to handle a "partial
load"?

Michael

"Arsen V." wrote:
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

Nov 18 '05 #5
I concur with Narayana, I think that in your specific case, OPENXML is the
way to go for you.

--
Toby Herring
MCDBA, MCSD, MCP+SB
Need a Second Life?
http://secondlife.com/ss/?u=03e0e5b3...e80ee40119a65e
"Arsen V." <ar***@community.nospam> wrote in message
news:%2****************@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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Raj Kotaru | last post by:
Hi, In sqlplus, I can insert a single row using: insert into employee (name, salary, hiredate) values ('xyz', '86378', sysdate); Is there a modification of the insert command that will...
3
by: JB | last post by:
To anyone that is able to help.... What I am trying to do is this. I have two tables (Orders, and OrderDetails), and my question is on the order details. I would like to set up a stored...
0
by: craftit | last post by:
hi everyone, i need to insert multiple rows in a single table using Oledbdataadapter for access database all in one trip in my winform(VB.Net). i've tried the best i can.Can anyone please help me...
4
by: Joanie | last post by:
I have a form that records dates of unavailability for a worker. Based on what is entered in the simple table behind the form, many calculations take place to create employee "load" balance. Each...
20
by: talktozee | last post by:
Hey, everyone! Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A. For...
3
Atli
by: Atli | last post by:
Hi. I've been trying to insert multiple rows into a table using a single INSERT statement in MSSQL / SQL Server 2005. I could of course cheat and have my C# code insert each row using some sort...
1
by: AlexW | last post by:
Hi I have been scouring the web for some information regarding how to insert multiple rows at once using an SQL string. I am using an OLEDB dataadapter to communicate with an MS Access DB ...
16
by: jasone | last post by:
Hi all, The system im working on currently allows the user to select a number of flowers.. click submit and whatever they clicked is passed onto the next page, i now want them to click order and...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.