USE AdventureWorks

-- Data Corruption; the Brenda's and the Richard's got mixed up.
-- Brenda Blumberg is a Sales Manager - Territory5
-- Brenda Marshall is a Tool Designer
-- Richard Runyan is a Benefits Specialist
-- Richard Skuce is a Production Technician - WC30

-- One person is changing 
--   Brenda Blumberg to Sales Manager - Territory5
--   Richard Skuce to Production Technician - WC30

-- Another person is changing 
--   Brenda Marshall to Tool Designer
--   Richard Runyan to Benefits Specialist

SELECT TOP 100 FirstName, LastName, Title FROM NewEmployee
WHERE FirstName in ('Brenda', 'Richard')

select FirstName, count(*) from Employee
GROUP BY FirstName
ORDER BY 2 DESC

GO

USE AdventureWorks
BEGIN TRAN
  UPDATE NewEmployee WITH (PAGLOCK)
  SET Title = 'Sales Manager - Territory5'
  WHERE FirstName = 'Brenda' AND LastName = 'Blumberg'

  UPDATE NewEmployee  WITH (PAGLOCK)
  SET Title = 'Production Technician - WC30'
  WHERE FirstName = 'Richard' AND LastName = 'Skuce'


COMMIT TRAN
GO


--USE AdventureWorks
-- --This Transaction will be run on another connection

--BEGIN TRAN
--  UPDATE NewEmployee WITH (PAGLOCK)
--  SET Title = 'Benefits Specialist'
--  WHERE FirstName = 'Richard' AND LastName = 'Runyan'

--  UPDATE NewEmployee WITH (PAGLOCK)
--  SET Title = 'Tool Designer'
--  WHERE FirstName = 'Brenda' AND LastName = 'Marshall'


--COMMIT TRAN


exec sp_lock
select @@spid
