I have a statement with a single UPDATE command. If I manually terminate it will all the results be rolled back?
+3
A:
If no errors occur then this statement cannot be rolled back
Update table
Set MyCol = 'foo'
Where MyOtherCol = 'bar'
However, what you can do in SQL is run the following statements together:
begin transaction
Update table
Set MyCol = 'foo'
Where MyOtherCol = 'bar'
Then perform any checks that you may need to do. If everything is ok then you can run the following.
commit transaction
if you need to cancel the update you can run this
rollback transaction
Barry
2010-09-16 07:53:30
+1
A:
If you kill the connection on which the update was issued, or otherwise manage to cancel the query, the update will be rolled back. Every DML statement in SQL runs within the context of a transaction - SQL Server will automatically create one if one doesn't exist, and commit it after the statement completes.
Damien_The_Unbeliever
2010-09-16 07:59:33