0

Let's say I have some C# code that executes two SQL commands:

var MyTransaction = DbConnection.BeginTransaction();
//using MyTransaction: INSERT INTO TABLE_1 (ID, SOURCE_FIELD) VALUES (99, 'HELLO')
//using MyTransaction: UPDATE TABLE_2 SET DESTINATION_FIELD = (SELECT SOURCE_FIELD FROM TABLE_1 WHERE ID = 99)
MyTransaction.Commit();

Will the second SQL statement see the new record with ID '99' even though I didn't commit the transaction until the end?

user3163495
  • 2,425
  • 2
  • 26
  • 43
  • 1
    Yes it will be available. – mjwills Mar 04 '21 at 00:26
  • 1
    Yes it will, but only for that session (exception: when using `read uncommitted/nolock`, or when binding to another session with `sp_bindsession` the you can see someone else's uncommitted rows) – Charlieface Mar 04 '21 at 00:28
  • 1
    Yes, because it is in the same transaction. If you ran the query separately in another session, the records would not be visible. – Gordon Linoff Mar 04 '21 at 00:59

0 Answers0