PrepAway - Latest Free Exam Questions & Answers

What should you do?

You are a database developer. You develop a database by using SQL Server 2008 in an enterprise environment. The database has a table named Sales.Inventory. The table is partitioned into four geographic regions. You update the Sales.Inventory table for each region by using the following stored procedure:

CREATE STORED PROCEDURE usp_Update
@RegionID tinyint
AS
UPDATE Sales.Inventory
SET Qty = T.CurrentQuantity
FROM Sales.Inventory I
JOIN Sales.TempData T ON I.ItemID = T.ItemID
AND I.RegionID = @RegionID;

The UPDATE statement locks the Sales.Inventory table when a single region is updated. You need to prevent the locking of the Sales.Inventory table when a single region is updated. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Modify the usp_Update stored procedure to use the NOLOCK table hint for the UPDATE statement.

B.
Modify the usp_Update stored procedure to use the SERIALIZABLE table hint for the UPDATEstatement.

C.
Run the following Transact-SQL statement. ALTER TABLE Sales.Inventory SET LOCK_ESCALATION = AUTO

D.
Run the following Transact-SQL statement. ALTER TABLE Sales.Inventory SET LOCK_ESCALATION = TABLE

Explanation:
In SQL Server 2008 ALTER TABLE statement, you can find a new option called SET LOCK_ESCALATION. This is one of the enhancement in Locking in SQL Server 2008. This option can have three value, Auto,Table, Disable

SET ( LOCK_ESCALATION = { AUTO | TABLE | DISABLE } )
Specifies the allowed methods of lock escalation for a table.

AUTO
This option allows SQL Server Database Engine to select the lock escalation granularity that is appropriate for the table schema.
If the table is partitioned, lock escalation will be allowed to the heap or B-tree (HoBT) granularity. After the lock is escalated to the HoBT level, the lock will not be escalated later to TABLE granularity.
If the table is not partitioned, the lock escalation will be done to the TABLE granularity.

TABLE
Lock escalation will be done at table-level granularity regardless whether the table is partitioned or not partitioned. This behavior is the same as in SQL Server 2005. TABLE is the default value.

DISABLE
Prevents lock escalation in most cases. Table-level locks are not completely disallowed. For example, when you are scanning a table that has no clustered index under the serializable isolation level, Database Engine must take a table lock to protect data integrity.

Note : If you use partitions then After you create a partitioned table, consider setting the LOCK_ESCALATION option for the table to AUTO. This can improve concurrency by enabling locks to escalate to partition (HoBT) level instead of the table. For more information


Leave a Reply