USE AdventureWorks

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

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

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

SELECT TOP 100 FirstName, LastName, Title FROM Person.Contact
WHERE FirstName in ('Brittney', '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 = 'Brittney' AND LastName = 'Blumberg'

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


rollback 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 = 'Brittney' AND LastName = 'Marshall'


--COMMIT TRAN


exec sp_lock
select @@spid

select * from person.contact
 WHERE FirstName = 'Richard' AND LastName = 'Marshall'
