Can someone please explain when and why use commit?
http://msdn.microsoft.com/en-us/library/ms190295.aspx
.
1) Update in tableX recordM
2) Update in tableY recordN
3) Update in tableZ recordO
4) use commit here
..
In the case where 2) fails and recordN is not updated, then roll back and do not proceed to 3) and 4) commit? is that where you would use it?
use commit whenver one or several operation (transaction) are finished, and you wish to make change the data base.
in your example, if 2) failed, you should do rollback and them the operation 1) will undo, so that will keep your database consistent
eg. if you have a bookshop system, whenever you sell a book you have to do several operations:
you will want either all operations done with success or nothing be done.
so you should:
if something wrong, rollback(undo) all