(MSSQL2000) I have read the transaction/locking sections in the
MS-help, online and several books. What I want to understand is the
transaction behavior in single statements [not a BEGIN TRANSACTION
Statement1, Statement2... COMMIT].
If I have a Table: "Letters" with 1 column "L" and the table presently
has rows{A,B,C,D}
Case 1 (Insert):
First start transaction T1 "SELECT * FROM Letters"
Next start transaction T2 [separate connection] "INSERT INTO Letters
VALUES( 'Z' )"
Is it possible that T2 ends before T1 and the select returns
{A,B,C,D,Z}
Is it possible that T1 ends before T2 and the select returns
{A,B,C,D} [No 'Z']
Is this a race condition and I need to use a TABLOCK or TABLOCKX;
and are TABLOCK/TABLOCKX only hints? I mean does the use of TABLOCK
guarantee a lock on the table? Do I need to use 'SET TRANSACTION
ISOLATION LEVEL SERIALIZABLE' and if I use 'TRANSACTION ISOLATION
LEVEL' is there a means of telling the system which tables I will
touch so that I can avoid a deadlock [upfront tell the system what
tables I need to lock so there is not a race later]?
Case 2 (Delete basically the same):
First start transaction T1 "SELECT * FROM Letters"
Next start transaction T2 "DELETE FROM Letters L = 'D'"
Is it possible that T2 ends before T1 and the select returns {A,B,C}
[No 'D']
Is it possible that T1 ends before T2 and the select returns
{A,B,C,D}
Case 3 (Update basically the same):
First start transaction T1 "SELECT * FROM Letters"
Next start transaction T2 "UPDATE Letters SET L = 'Z'"
Is it possible that T2 ends before T1 and the select returns
{A,B,Z,Z} [Some letters were seen to become 'Z']
Is it possible that T1 ends before T2 and the select returns
{A,B,C,D}