473,289 Members | 1,961 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,289 software developers and data experts.

Large number of INSERT statements - not all are executed

Hello!

I have a developer that is playing around with some SQL statements
using VB.NET. He has a test table in a SQL 2000 database, and he has
about 2000 generated INSERT statements.

When the 2000 INSERT statements are run in SQL query analyzer, all
2000 rows are added to the table. When he tries to send the 2000
statements to SQL Server through his app., a random number of
statements do not get executed. But, SQL Profiler shows that each of
the 2000 statements are getting sent to the server.

I suggested that he add a "GO" statement at the end of the INSERT
block, but the statement fails when that is sent to the server.

I know that this is not the ideal manner to insert bulk data to the
system, but now we are all just curious as to why SQL server doesn't
execute each individual INSERT.

Any thoughts?

Feb 9 '07 #1
3 6578
Hi Dmitri,
I have a developer that is playing around with some SQL statements
using VB.NET. He has a test table in a SQL 2000 database, and he has
about 2000 generated INSERT statements.

When the 2000 INSERT statements are run in SQL query analyzer, all
2000 rows are added to the table. When he tries to send the 2000
statements to SQL Server through his app., a random number of
statements do not get executed. But, SQL Profiler shows that each of
the 2000 statements are getting sent to the server.
How were the statements sent to SQL Server?
One batch with 2k statements or one statement per batch?
What about transactions (autocommit mode)?
What events were set to be captured by Profiler?
I suggested that he add a "GO" statement at the end of the INSERT
block, but the statement fails when that is sent to the server.
Wrong suggestion. "GO" is not an SQL statement and can be used only in
Query Analyzer (Enterprise Manager, Management Studio). It signals the
end of a batch to MSSQL utilities, SQL Server doesn't understand it at all.
--
Best regards,
Marcin Guzowski
http://guzowski.info
Feb 9 '07 #2
Dmitri,

SQL Server doesn't just ignore transactions. If the statements are showing
up in SQL Server Profiler, then SQL is executing or attempting to execute
them. There may be other reasons why you are not getting the expected
results. Try these steps:

1. Backup the database.
2. Run a trace. Remove the Existing Connection and Audit events before
starting the trace. They are not necessary for this exercise and create
additional noise. You may want to set up a filter that captures only the
application being tested.
3. Save the trace as a SQL Script.
4. Restore the database.
5. Open the SQL Script and run it.
6. See if there are any errors or warnings that are not being trapped by the
VB.NET application.

-- Bill

"Dmitri" <ni*********@gmail.comwrote in message
news:11********************@s48g2000cws.googlegrou ps.com...
Hello!

I have a developer that is playing around with some SQL statements
using VB.NET. He has a test table in a SQL 2000 database, and he has
about 2000 generated INSERT statements.

When the 2000 INSERT statements are run in SQL query analyzer, all
2000 rows are added to the table. When he tries to send the 2000
statements to SQL Server through his app., a random number of
statements do not get executed. But, SQL Profiler shows that each of
the 2000 statements are getting sent to the server.

I suggested that he add a "GO" statement at the end of the INSERT
block, but the statement fails when that is sent to the server.

I know that this is not the ideal manner to insert bulk data to the
system, but now we are all just curious as to why SQL server doesn't
execute each individual INSERT.

Any thoughts?

Feb 9 '07 #3
Dmitri (ni*********@gmail.com) writes:
I have a developer that is playing around with some SQL statements
using VB.NET. He has a test table in a SQL 2000 database, and he has
about 2000 generated INSERT statements.

When the 2000 INSERT statements are run in SQL query analyzer, all
2000 rows are added to the table. When he tries to send the 2000
statements to SQL Server through his app., a random number of
statements do not get executed. But, SQL Profiler shows that each of
the 2000 statements are getting sent to the server.

I suggested that he add a "GO" statement at the end of the INSERT
block, but the statement fails when that is sent to the server.

I know that this is not the ideal manner to insert bulk data to the
system, but now we are all just curious as to why SQL server doesn't
execute each individual INSERT.
Did he send one batch with 2000 statements, or 2000 batches? Without
seeing the code, it's difficult to know what we are talking about.

The most effective way of inserting data this way is:

INSERT tbl (....)
EXEC('SELECT ''thisvalue'', 1, ''thatvalue''
SELECT ''thisothervalue'', 2, ''thatothervalue''
...')

This keeps it down to one INSERT statement, but many small SELECT
statements that are easy to compile. (The alternative SELECT UNION
is very expensive to compile for 2000 rows.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 9 '07 #4

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

Similar topics

4
by: Paul | last post by:
I have run into a strange problem with a site I am working on. My SELECT queries work fine, but I just tried to add an UPDATE statement and it fails. A test showed that INSERT fails also. I created...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
6
by: jcrouse | last post by:
Here is a sniplet from a text file game name mapp description "Mappy (US) year 198 manufacturer "Namco history "\nMappy (c) 03/1983 Namco. \n\n- TRIVIA: \n\nLicensed to Bally Midway for US...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
2
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even...
10
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has...
0
by: Sam Durai | last post by:
Hello, is there is any snapshot element availble which could give the no of uncommited Insert/Update/Delete stmts there were executed by an application. In the app shap I understand that this...
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
1
by: tim999 | last post by:
Hi everyone, I've been working on a large data extract and was wandering if anyone could take a look at the following code and offer any reasons why it takes such a long time compared to when i...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.