Re: Update time

From: Louis Davidson (dr_dontspamme_sql_at_hotmail.com)
Date: 11/17/04


Date: Wed, 17 Nov 2004 17:57:40 -0600

Because you are not doing the same thing in each case, right?

 Update Positions
 Set Sec_class = null

<>

      Update Positions
      Set Sec_class = null
       Where Position_Date = '20040101'

      Update Positions
      Set Sec_class = null
       Where Position_Date = '20040102'

...

      Update Positions
      Set Sec_class = null
       Where Position_Date = <last date>

Because you are not within a transaction. If setting Sec_class = null fails
for '20040401' then you are not going to rollback anything other than those
rows on '20040401'. Not ones previous. So thes modifications can be
flushed to the hard disk permanently and not be worried about again. On the
other hand, SQL Server must prepare to rollback if any row fails. This
overhead, plus the increasing lock count cause things to start to slow down
exponentially as you hit the hardware limitations of your computer. If you
wrap your updates in:

BEGIN TRANSACTION
...
COMMIT TRANSACTION

You may get the same sort of performance. I hope this makes sense because
it is really a very important concept. Every single statement, or every
single group of statements in a transaction have to occur together, and they
have to be isolated from everyone else, so the bigger the load, the harder
it is to do this.

-- 
----------------------------------------------------------------------------
Louis Davidson - drsql@hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design - 
http://www.apress.com/book/bookDisplay.html?bID=266
Note: Please reply to the newsgroups only unless you are interested in 
consulting services.  All other replies may be ignored :)
"DWalker" <None> wrote in message 
news:%2353OD8OzEHA.1300@TK2MSFTNGP14.phx.gbl...
> "Louis Davidson" <dr_dontspamme_sql@hotmail.com> wrote in
> news:OMfQjDOzEHA.3416@TK2MSFTNGP09.phx.gbl:
>
>> SQL Server can, but can the hardware?  I had SQL Server on one of my
>> home computers that had 128 MB of RAM and one single disk drive.  I
>> could put a 10 gig database on there, and update every row in a 50
>> million row table, but how long should this take?
>>
>> Uri's suggestion basically was a very common suggestion to balance
>> inadequate resources versus larger needs.
>>
>
> A followup -- yes, the hardware can, if it's done a batch at a time.
> The odd thing is that SQL server picks a bad way to do it if it's not
> batched.  I don't think the size of the log file is the problem; it
> seems rather like SQL is picking a bad execution plan to update the
> whole table at once.  If *I* can figure out that updating a small batch
> at a time is faster, why can't the fancy Query Optimizer figure out the
> same thing, and do batching behind the scenes?
>
> David Walker 


Relevant Pages

  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.sqlserver.server)
  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.sqlserver.programming)
  • Re: Inserting Multiple Rows
    ... In addition to that [BCP, BULK INSERT, DTS], it might be worth mentioning below two things. ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Efficient INSERT of rows- .NET
    ... In case Jon wants to stick with INSERT ... Group several INSERT in the same transaction. ... Each batch requires a network roundtrip, ... mean what we see as "GO" in Query Analyzer and the method you use in ADO.NET to send the command to SQL Server ...
    (microsoft.public.sqlserver.programming)
  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)

Loading