--------------------------------------------------------------------------------
--  File        :   Demo 02_ProcessB.sql
--
--  Purpose     :   This script is half of a demonstration of creating a 
--                  deadlock.  Open this script in one tab of SSMS and the 
--                  "Demo 02_ProcessA.sql" script in another tab.
--
--                  NOTE: This code is based on an example from:
--                      "Sample: Creating a SQL Server Agent Alert by Using the WMI Provider for Server Events" <http://msdn.microsoft.com/en-us/library/ms186385(SQL.90).aspx>
--
--                  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.0018 (2010-05-31)
--------------------------------------------------------------------------------

/*  Instructions  */

--  1.  Open the "Demo 02_ProcessA.sql" script in one tab of SSMS.
--  2.  Open this script in another tab.
--  3.  Execute the "Demo 02_ProcessA.sql" script without selecting any of the 
--      code.
--  4.  Execute this script without selecting any of the code.
--  5.  In the first tab, select/highlight the text in lines 49 through 50.
--  6.  Press the F5 button to execute the selected code.
--  7.  Wait for the this script to be chosen as the deadlock victim.
--  8.  In the first tab, select/highlight the text in line 54.
--  9.  Press the F5 button to execute the selected code.

USE [AdventureWorks];

GO

BEGIN TRANSACTION;

SELECT TOP (1) [Name]
FROM [Production].[Location] WITH (XLOCK);

SELECT TOP (1) [Name]
FROM [Production].[Product] WITH (XLOCK);

/*
ROLLBACK TRANSACTION;
*/
