Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-30 : 10:47:23
|
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 = 1When 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
12543 Posts |
Posted - 2006-08-30 : 10:51:06
|
WHat indexes do you have on the tables.Try stage batch_status, aIdand transaction aIdalso the second update should beUpdate transactionSet b = s.b,from stage sWhere 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. |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-08-30 : 11:26:39
|
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? |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-30 : 11:42:12
|
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. |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-08-30 : 16:04:49
|
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. |
|
|
|
|
|
|
|