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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Stopping an Update Query

Author  Topic 

Job
Yak Posting Veteran

69 Posts

Posted - 2005-11-30 : 17:11:57
I assume if I start an update query then stop it, sql undoes whatever updates it made, this is why it often takes a long time. Is there a way to actually STOP? If it is an update that I don't mind if it rolls back the transaction can I force it to stop immediately?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-30 : 18:00:10
A rollback is required if the transaction is terminated/killed. There is no way to leave it partially committed. If even you turned off the database server to force a stop, SQL Server would decide to roll it back at startup if the transaction didn't complete. Rolling forward and backwards of transactions is performed by SQL Server at startup to ensure that we have a consistent database.

Tara Kizer
aka tduggan
Go to Top of Page

Job
Yak Posting Veteran

69 Posts

Posted - 2005-11-30 : 19:23:40
Ok. That makes sense. Thanks for the info.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-01 : 00:45:40
If you've got a massive update to do you could do it in batches - so that you can interrupt it

SET ROWCOUNT 1000
UPDATE U
SET MyColumn = 'FOO'
FROM MyTable AS U
WHERE MyColumn = 'BAR'
SET ROWCOUNT 0 -- Reset the limit!!

put this in a loop (checking the @@ROWCOUNT until it is zero) if you want it to run until completion, if you abort it the rows already processed will be kept (take care that it isn't in a transaction block such that the whole lot gets rolled back!)

Kristen
Go to Top of Page
   

- Advertisement -