Using SQL transactions for operations involving multiple steps