views:

71

answers:

2

Case 1:

  1. I start a connection to the DB
  2. I BEGIN a TRANSACTION
  3. I close the connection

    What happens to the transaction?

Case 2:

  1. I start a connection to the DB
  2. I BEGIN a TRANSACTION
  3. I start a concurrent connection to the same DB
  4. With the second connection I modify the contents of a table
  5. With the first connection I ROLLBACK the TRANSACTION

    What happens to the modifications?

+2  A: 

Case 1: roll back

Case 2: at step 4, you can't modify rows which are touched by the first connection so there's no effect: the second connection can't modify, it will wait (due to the locks).

Frans Bouma
What is this "touch" thing? If the first connection modifies row 1 of table A, it means that the other rows are untouched and they can be modified by the second connection during the transaction?
Jader Dias
that depends on the locks taken by sql server.
Mladen Prajdic
@Jader: 'touched' as in: read/modified as connection 1 sets locks on the rows read/modified and connection 2 has to obey those. If the 1st transaction is set to readuncommitted as isolation, connection two may read modified rows, but not alter them
Frans Bouma
+1  A: 

Just to add: Transactions are session dependent - this explains your first question.

Sam