Saturday, February 25, 2012

A question on Isolation level

Whenever the update statment is executed the patient table will be
locked even for the querying. Is there a way
where in the select locks the table so that the other transaction will
not even able to select.
If change the isolation level to repeatable read or higher it will not
allow update and insert by other transaction
but select will be allowed which I want to stop
SQL
--
BEGIN TRAN
SELECT * FROM PATIENT WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
WAITFOR DELAY '00:00:10'
COMMIT TRANI don't understand why you have the waitfor statements. My understanding of
how the lock manager works is that it will escalate the number of locks it
has to place based on the indexes in place and the perceived numbers of rows
it has to update.
So if you have an index in place on the status column and only a few rows of
a large table have a value of A row level locking should occur. If there are
no indexes or depending on the number of rows, it could be page level,
extent locks or a table lock.
I would update statsitics, evaluate how many rows are affected to see if you
can't change this behavior.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"shiju" <shiju.samuel@.gmail.com> wrote in message
news:1156937237.329228.258100@.m73g2000cwd.googlegroups.com...
> Whenever the update statment is executed the patient table will be
> locked even for the querying. Is there a way
> where in the select locks the table so that the other transaction will
> not even able to select.
> If change the isolation level to repeatable read or higher it will not
> allow update and insert by other transaction
> but select will be allowed which I want to stop
>
> SQL
> --
> BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> COMMIT TRAN
>|||On 30 Aug 2006 04:27:17 -0700, "shiju" <shiju.samuel@.gmail.com> wrote:
>Whenever the update statment is executed the patient table will be
>locked even for the querying. Is there a way
>where in the select locks the table so that the other transaction will
>not even able to select.
>If change the isolation level to repeatable read or higher it will not
>allow update and insert by other transaction
>but select will be allowed which I want to stop
try "select * from patient with (updlock) where status = 'A'"
>
>SQL
>--
>BEGIN TRAN
> SELECT * FROM PATIENT WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
> UPDATE PATIENT SET STATUS = 'I' WHERE STATUS = 'A'
> WAITFOR DELAY '00:00:10'
>COMMIT TRAN

No comments:

Post a Comment