Unix Technical Forum

Large number of INSERT statements - not all are executed

This is a discussion on Large number of INSERT statements - not all are executed within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello! I have a developer that is playing around with some SQL statements using VB.NET. He has a test ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 01:17 PM
Dmitri
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 01:17 PM
Marcin A. Guzowski
 
Posts: n/a
Default Re: Large number of INSERT statements - not all are executed

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 01:17 PM
AlterEgo
 
Posts: n/a
Default Re: Large number of INSERT statements - not all are executed

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" <nienna.gaia@gmail.com> wrote in message
news:1171036327.517795.9440@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?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 01:17 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Large number of INSERT statements - not all are executed

Dmitri (nienna.gaia@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, esquel@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com