--------------------------------------------------------------------------------
--  File        :   Demo 09_Changing the deadlock priority_ProcessA.sql
--
--  Purpose     :   This script is half of a demonstration of creating a 
--                  deadlock while specifying a non-default deadlock 
--                  priority.  It is the same as the "Demo 01_ProcessA.sql" 
--                  demonstration script, except for the setting of the 
--                  DEADLOCK_PRIORITY option.  Open this script in one tab of 
--                  SSMS and the 
--                  "Demo 09_Changing the deadlock priority_ProcessB.sql" 
--                  script in another tab.
--
--                  NOTE: This code is based on an example from:
--                      _Inside Microsoft SQL Server 2005: The Storage Engine_ by Kalen Delaney (ISBN 9780735621053)
--
--                  NOTE: This script depends on the [AdventureWorks] 
--                  database, not the [AdventureWorks2008] database.  The 
--                  [AdventureWorks] database will work on both SQL Server 
--                  2005 and 2008 and can be downloaded from:
--                      "SQL Server 2005 SP2a" <http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004>
--
--  SQL Server  :   SQL Server 2005 (9.0)
--                  SQL Server 2008 (10.0)
--                  SQL Server 2008 R2 (10.5)
--
--  Version     :   3.0006.0090.0053 (2010-11-17)
--------------------------------------------------------------------------------

/*  Instructions  */

--  1.  Open this script in one tab of SSMS.
--  2.  Open the "Demo 08_Changing the deadlock priority_ProcessB.sql" script 
--      in another tab.
--  3.  Execute this script without selecting any of the code.
--  4.  Execute the "Demo 08_Changing the deadlock priority_ProcessB.sql" 
--      script without selecting any of the code.
--  5.  In the first tab, select/highlight the text in the first comment block 
--      below (lines 65 through 68).
--  6.  Press the F5 button to execute the selected code.
--  7.  In the second tab, select/highlight the text in the comment block 
--      (lines 53 through 60).
--  8.  Press the F5 button to execute the selected code.
--  9.  Wait for this script to be chosen as the deadlock victim.
--  10. In the second tab, select/highlight the text in the second comment 
--      block (line 64).
--  11. Press the F5 button to execute the selected code.

USE [AdventureWorks];

GO

SET DEADLOCK_PRIORITY LOW;

BEGIN TRANSACTION;

UPDATE [Purchasing].[PurchaseOrderDetail]
SET [OrderQty] = [OrderQty] + 200
WHERE
(
    ([ProductID] = 922)
    AND
    ([PurchaseOrderID] = 499)
);

/*
--  Select the contents of this comment block as Step 5.
UPDATE [Production].[Product]
SET [ListPrice] = [ListPrice] * 0.9
WHERE ([ProductID] = 922);
*/

/*
ROLLBACK TRANSACTION;
*/

GO
