SQL Server Questions and Answers – Blocking

This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Blocking”.

1. Which of the following design strategy can reduce the occurrence of blocking locks?
a) Use non-clustered indexes on high-usage tables
b) Use clustered indexes on high-usage tables
c) Use clustered indexes on less-usage tables
d) Make sure that CREATE and DROP statements use an existing index
View Answer

Answer: b
Explanation: Clustered index should be created on frequently used tables.

2. Point out the correct statement.
a) Avoid less row count SQL statements that can cause a table lock
b) A blocking lock occurs when one lock causes another process to wait in a holding queue
c) Lock is a done by database when any connection access a different piece of data concurrently
d) None of the mentioned
View Answer

Answer: b
Explanation: If blocking locks are common (rather than infrequent), there is probably some kind of design or query implementation problem.

3. Which of the following scenario give rise to deadlock (There are 2 processes)?
a)

P1 & P2 trying TO GET TO 2 resources R1 & R2.
P1 gets a LOCK ON R2
AND
P2 gets a LOCK ON R2
THEN
P1 tries TO GET a LOCK ON R2 but can’t because it IS locked BY P2
AND
P2 tries TO GET a LOCK ON R1 but can’t because it IS locked BY P1

b)

advertisement
advertisement
 P1 & P2 trying TO GET TO 2 resources R1 & R2.
P1 gets a LOCK ON R1
AND
P2 gets a LOCK ON R1
THEN
P1 tries TO GET a LOCK ON R2 but can’t because it IS locked BY P2
AND
P2 tries TO GET a LOCK ON R1 but can’t because it IS locked BY P1

c)

 P1 & P2 trying TO GET TO 2 resources R1 & R2.
P1 gets a LOCK ON R1
AND
P2 gets a LOCK ON R2
THEN
P1 tries TO GET a LOCK ON R2 but can’t because it IS locked BY P2
AND
P2 tries TO GET a LOCK ON R1 but can’t because it IS locked BY P1

d) All of the mentioned
View Answer

Answer: c
Explanation: Deadlock occurs when one connection is blocked and waiting for a second to complete its work.

advertisement

4. Which of the following occurs when two connections need access to same piece of data concurrently and the meanwhile another is blocked because at a particular time, only one connection can have access?
a) Lock
b) Block
c) Deadlock
d) Exclusive lock
View Answer

Answer: b
Explanation: Lock is done by database when any connection access the same piece of data concurrently and another is demanding for it.

advertisement

5. Point out the wrong statement.
a) SQL Server lock monitor has a performance monitor that periodically checks the locks
b) A deadlock graph shows us the sessions and resources that were involved in a deadlock
c) Prior to SQL Server 2008, if a deadlock occurred in SQL Server, we’d have to enable trace flag
d) None of the mentioned
View Answer

Answer: a
Explanation: SQL Server lock monitor has a deadlock detector that periodically checks the locks to see if there are any circular locking chains.

6. An XML deadlock graph has ______ main sections.
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: a
Explanation: An XML deadlock graph has two main sections: Processes section and Resources section.

7. _____________ section lists all the resources that were involved in the deadlock.
a) Processes
b) Resources
c) WAIT stats
d) All of the mentioned
View Answer

Answer: b
Explanation: Resources section lists all the resources that were involved in the deadlock, which locks each process acquired and which locks they requested.

8. ___________ is a deadlock between a statement that is reading and a statement that is performing some form of data modification.
a) Reader
b) Writer
c) Reader-Writer
d) All of the mentioned
View Answer

Answer: c
Explanation: When you look at the resources involved, you’ll see that the signature of this form of deadlock is locked that are all either a shared (S) lock granted and an exclusive (X) lock requested or an X lock granted and an S lock requested.

9. Which of the following query returns object names from partition IDs?
a)

SELECT OBJECT_NAME(p.object_id) AS TableName , 
       i.name AS IndexName 
FROM sys.partition AS p 
     INNER JOIN sys.indexes AS i ON p.object_id = i.object_id 
                                    AND p.index_id = i.index_id 
WHERE partition_id = 72057594038845440

b)

SELECT OBJECT_NAME(p.object_id) AS TableName , 
       i.name AS IndexName 
FROM sys.partitions AS p 
     INNER JOIN sys.indexes AS i ON p.object_id = i.object_id 
                                    AND p.index_id = i.index_id 
WHERE partition_id = 72057594038845440

c)

SELECT OBJECT_NAME(p.object_id) AS TableName , 
       i.name AS IndexName 
FROM sys.partitions AS p 
     INNER JOIN sys.index AS i ON p.object_id = i.object_id 
                                    AND p.index_id = i.index_id 
WHERE partition_id = 72057594038845440

d) None of the mentioned
View Answer

Answer: b
Explanation: sys.partitions contains a row for each partition of all the tables and most types of indexes in the database.

10. Which of the following best practice should be carried out concerning data types?
a) Avoid using NOLOCK on SQL Server UPDATE and DELETE statements
b) Capturing SQL Server Deadlock Information in XML Format
c) Optimistic Locking in SQL Server using the ROWVERSION
d) Processing Data Queues in SQL Server with READPAST and UPDLOCK
View Answer

Answer: c
Explanation: Implementing optimistic locking utilizing the row version data type is an effective, low overhead way to prevent lost updates while still maintaining application concurrency.

Sanfoundry Global Education & Learning Series – SQL Server.

To practice all areas of SQL Server, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.