SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


LOCK


LOCK

Author
Message
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3738 Visits: 4408
Christian Buettner-167247 (2/18/2010)
Sorry, but option 1 is still wrong.
Exclusive locks prevent access to a resource by concurrent transactions


Read access is not prevented in case of NOLOCK or READ UNCOMMITTED

Exactly. Another option is 'ALTER DATABASE xxx SET READ_COMMITTED_SNAPSHOT ON'. This, unlike NOLOCK, does not violate one of the ACID principles (isolation).

I am also puzzled with the fourth answer:
Data modification statements typically request both shared locks and exclusive locks


The word 'typically' is so vague. For example, typically I work with databases with the READ_COMMITTED_SNAPSHOT option turned on. Data modification statements typically don't request shared locks in this case. So I didn't select the fourth answer.
Paul White
Paul White
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16212 Visits: 11355
Exclusive locks prevent access to a resource by concurrent transactions
Just a small correction is needed:
Exclusive locks prevent write access to a resource by concurrent transactions


vk-kirov (2/18/2010)
I am puzzled with the fourth answer:
Data modification statements typically request both shared locks and exclusive locks

The word 'typically' is so vague. For example, typically I work with databases with the READ_COMMITTED_SNAPSHOT option turned on. Data modification statements typically don't request shared locks in this case. So I didn't select the fourth answer.

I disagree. The majority of databases don't run under one of the row-versioning isolation levels, so use of the word 'typically' is justified.

The default isolation level in SQL Server is, and has always been, READ COMMITTED.

At that level of isolation, shared locks (or maybe update locks if requested) are taken by the read cursor, and escalated to exclusive locks by the write cursor if the row qualifies for modification.

I understand that you don't see shared locks very often in your environment (though you must have used WITH READCOMMITTEDLOCK at some stage!) but you should still be aware of the default behaviour.

Paul



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Saurabh Dwivedy
Saurabh Dwivedy
Mr or Mrs. 500
Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)

Group: General Forum Members
Points: 538 Visits: 340
Paul White (2/17/2010)


With an exclusive lock, no other transactions can modify data (except for operations with NOLOCK hint or read uncommitted isolation level)

What???!!! w00t

I want my point back!

Unless someone can post code or a reference to show that NOLOCK or READ UNCOMMITTED allows modification of data protected by an exclusive lock!

Grrr!



With an exclusive lock, no other transactions can modify data (read operations with NOLOCK hint or read uncommitted isolation level can take place),

The above choice states clearly that no other transaction can MODIFY data - which is correct; that being said, Read operations with NOLOCK hint or under read uncommitted isolation level can certain take place - REFER to the following link ----- http://www.sqlteam.com/article/introduction-to-locking-in-sql-server (exclusive lock section)

Exclusive locks prevent write access to a resource by concurrent transactions ,
I don't think there is any ambiguity in this choice - it is clear enough and correct - X Locks prevents any concurrent write access


Data modification statements typically request both shared locks and exclusive locks

I must admit that I was momentarily confused by the wording of this choice - I only answered it from gut feel; Typically DML operations should take an UPDATE lock; While Shared locks can be escalated to an exclusive lock when the DML kicks in, it can end up in a deadlock if another transaction (under shared lock mode) attempts to update the same data. To prevent this situation Update locks are used. Saying that Data Modification statements typically REQUEST both shared and exclusive locks does lead to an ambiguous situation. It could have been more appropriately worded.

Saurabh Dwivedy
___________________________________________________________

My Blog: http://tinyurl.com/dwivedys

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537

Be Happy!
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33146 Visits: 18560
Saurabh Dwivedy (2/18/2010)
Paul White (2/17/2010)


With an exclusive lock, no other transactions can modify data (except for operations with NOLOCK hint or read uncommitted isolation level)

What???!!! w00t

I want my point back!

Unless someone can post code or a reference to show that NOLOCK or READ UNCOMMITTED allows modification of data protected by an exclusive lock!

Grrr!



With an exclusive lock, no other transactions can modify data (read operations with NOLOCK hint or read uncommitted isolation level can take place),

The above choice states clearly that no other transaction can MODIFY data - which is correct; that being said, Read operations with NOLOCK hint or under read uncommitted isolation level can certain take place - REFER to the following link ----- http://www.sqlteam.com/article/introduction-to-locking-in-sql-server (exclusive lock section)

Exclusive locks prevent write access to a resource by concurrent transactions ,
I don't think there is any ambiguity in this choice - it is clear enough and correct - X Locks prevents any concurrent write access


Data modification statements typically request both shared locks and exclusive locks

I must admit that I was momentarily confused by the wording of this choice - I only answered it from gut feel; Typically DML operations should take an UPDATE lock; While Shared locks can be escalated to an exclusive lock when the DML kicks in, it can end up in a deadlock if another transaction (under shared lock mode) attempts to update the same data. To prevent this situation Update locks are used. Saying that Data Modification statements typically REQUEST both shared and exclusive locks does lead to an ambiguous situation. It could have been more appropriately worded.


The question originally stated (in essence) that a nolock hint could be used to modify while an exclusive lock was held. It has been changed since. Paul wasn't disputing that a read could happen while using the nolock hint if an exclusive lock was held - just that the wording was wrong and thus made that option incorrect.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Steve Jones
Steve Jones
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: Administrators
Points: 64661 Visits: 19118
Wording has been changed to make this more clear. I am awarding back points as well.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Saurabh Dwivedy
Saurabh Dwivedy
Mr or Mrs. 500
Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)Mr or Mrs. 500 (538 reputation)

Group: General Forum Members
Points: 538 Visits: 340
CirquedeSQLeil (2/18/2010)
Saurabh Dwivedy (2/18/2010)
Paul White (2/17/2010)


With an exclusive lock, no other transactions can modify data (except for operations with NOLOCK hint or read uncommitted isolation level)

What???!!! w00t

I want my point back!

Unless someone can post code or a reference to show that NOLOCK or READ UNCOMMITTED allows modification of data protected by an exclusive lock!

Grrr!



With an exclusive lock, no other transactions can modify data (read operations with NOLOCK hint or read uncommitted isolation level can take place),

The above choice states clearly that no other transaction can MODIFY data - which is correct; that being said, Read operations with NOLOCK hint or under read uncommitted isolation level can certain take place - REFER to the following link ----- http://www.sqlteam.com/article/introduction-to-locking-in-sql-server (exclusive lock section)

Exclusive locks prevent write access to a resource by concurrent transactions ,
I don't think there is any ambiguity in this choice - it is clear enough and correct - X Locks prevents any concurrent write access


Data modification statements typically request both shared locks and exclusive locks

I must admit that I was momentarily confused by the wording of this choice - I only answered it from gut feel; Typically DML operations should take an UPDATE lock; While Shared locks can be escalated to an exclusive lock when the DML kicks in, it can end up in a deadlock if another transaction (under shared lock mode) attempts to update the same data. To prevent this situation Update locks are used. Saying that Data Modification statements typically REQUEST both shared and exclusive locks does lead to an ambiguous situation. It could have been more appropriately worded.


The question originally stated (in essence) that a nolock hint could be used to modify while an exclusive lock was held. It has been changed since. Paul wasn't disputing that a read could happen while using the nolock hint if an exclusive lock was held - just that the wording was wrong and thus made that option incorrect.


Thanks Cirque... it sounds like I joined the party late when the question had already been modified...

Saurabh Dwivedy
___________________________________________________________

My Blog: http://tinyurl.com/dwivedys

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537

Be Happy!
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33146 Visits: 18560
Saurabh Dwivedy (2/18/2010)


Thanks Cirque... it sounds like I joined the party late when the question had already been modified...


You're welcome and NP.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Paul White
Paul White
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16212 Visits: 11355
Thanks for having my back there Jason Cool



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Tom Thomson
Tom Thomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14562 Visits: 12238
I'm glad it had been edited (twice) by the time I saw it - at least the answer is now right. The explanation is still slighly wrong, though: the first sentence suggests that all concurrent access is prevented, but in fact read access is allowed if it uses the right "isolation" level (quote marks because I would call READ UNCOMITTED an "unisolation level").

Tom

Malcolm Daughtree
Malcolm Daughtree
SSC Veteran
SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)

Group: General Forum Members
Points: 293 Visits: 335
Data modification statements typically request both shared locks and exclusive locks !!

from MSDN

When lock escalation occurs, the lock selected for the heap or index is strong enough to meet the requirements of the most restrictive lower level lock.

Not at the same time and what about the issuing of IXWhen lock escalation occurs, the lock selected for the heap or index is strong enough to meet the requirements of the most restrictive lower level lock.

For example, assume a session:

Begins a transaction.

Updates a table containing a clustered index.

Issues a SELECT statement that references the same table.

The UPDATE statement acquires these locks:
Exclusive (X) locks on the updated data rows.
Intent exclusive (IX) locks on the clustered index pages containing those rows.
An IX lock on the clustered index and another on the table.

The SELECT statement acquires these locks:
Shared (S) locks on all data rows it reads, unless the row is already protected by an X lock from the UPDATE statement.
Intent Share locks on all clustered index pages containing those rows, unless the page is already protected by an IX lock.
No lock on the clustered index or table because they are already protected by IX locks.

There are more answers than those provided.

CodeOn
:-P
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search