I have 2 tables in my database. They are Item and Field. Item is a self referenced table to implement a tree. That means in Item table, I have ID and ParentId columns. In this way, we can store a tree in the Item table. Field is a table to store other extend properties for an item. Field table has a column named "Item_ID" to refer to item table.
OK, now we just want to add transaction to the database operation. We found some strange behavior as the title.
As Microsoft asked, we run the following sql to enable snapshot isolation of our database:
ALTER DATABASE AdventureWorks2008R2
SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE AdventureWorks2008R2
SET ALLOW_SNAPSHOT_ISOLATION ON;
And then we do the following test:
Open 2 test programs
The first program update Item 1 and be blocked before the transaction is commit.
Use the second program to try to delete Item 2. Item 1 have no relation ship with Item 2. That means Item 1 do not is a parent/child of Item 2.
Then we found second program is blocked by first program. If we continue the first program, then we second program will finish if it is not timeout.
I feel strange about this result. Because I think I can delete Item 2 even Item 1 is in transaction. Who knows why this happens?