SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating 4 million Records
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 08/30/2006 :  10:47:23  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Meg writes "Hi,

I have a table that has 4+ million records. I need to update those records. I am facing some performance issue. Can someone please advice?

update stage
set batch_status = 1
where update_status = 0


Update transaction
Set aId = s.aId,
b = s.b,

from stage s
Where s.aId = transaction.aId
and s.batch_status = 1


Update stage
Set update_status = 1,
batch_status = 2

where

batch_status = 1

When I run the above query with "set rowcount 1000", it runs in one minute. When I run the query for "set rowcount 10000", it runs in 1 hour 56 minutes. Can someone help me to optimize it?

Thanks.
Meg"

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 08/30/2006 :  10:51:06  Show Profile  Visit nr's Homepage  Reply with Quote
WHat indexes do you have on the tables.
Try
stage batch_status, aId

and
transaction aId

also the second update should be

Update transaction
Set b = s.b,
from stage s
Where s.aId = transaction.aId
and s.batch_status = 1


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nr on 08/30/2006 10:52:17
Go to Top of Page

blindman
Flowing Fount of Yak Knowledge

USA
2365 Posts

Posted - 08/30/2006 :  11:26:39  Show Profile  Reply with Quote
If batch_status is boolean then indexing it may not help. As a matter of fact, she might be better off temporarily removing some of the indexes from the table.

Meg, give us a list of the indexes on the tables, as nr suggested.

Also, try running the script for 1000 records through Query Analyzer and check out the execution plan. What does it say is taking up the majority of the time?

Edited by - blindman on 08/30/2006 11:29:39
Go to Top of Page

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 08/30/2006 :  11:42:12  Show Profile  Visit nr's Homepage  Reply with Quote
Even if batch status is a boolean it will still help as long as the search is on the value with the smailler number of rows.

I assume the rowcount is used for the set of this value in the first query.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nr on 08/30/2006 11:42:49
Go to Top of Page

blindman
Flowing Fount of Yak Knowledge

USA
2365 Posts

Posted - 08/30/2006 :  16:04:49  Show Profile  Reply with Quote
In my testing, a BIT value always resulted in an index scan, regardless of cardinality.
When the boolean value was represented in a smallint column an index seek was always used, regardless of cardinality.
So it may depend upon the datatype. Perhaps the server always performs scans on BIT data columns.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000