I thought I understood the locking mechanism from SQL, but it seems that I do not. I do know that you can have shared and exclusive locks and that 2 shared locks can be applied at the same data at the same time. But can someone explain me why query 1 doesn't block query 2. I expect that the serializable keyword will give me a exclusive lock instead of a shared lock. To get concrete:
I created a user table:
- id [int]
- name [nvarchar50)
Than I opened sql management studio connected to that database with user1 and execute the following query:
BEGIN TRAN
select * from [user] WITH(SERIALIZABLE, TABLOCK, HOLDLOCK)
I keep the transaction open on purpose.
Than I open a second sql mangement studio connect to the same database with user2 and execute the same query. I Expected that 2nd query keeps running, since query 1 is remaining a lock on the table, but it doesnt. The 2nd query is executed directly. Why is this? Are my lock hints ignored?