--Clean out existing rows from PROJECTIONS and P_Audit
DELETE FROM PROJECTIONS;
DELETE FROM P_AUDIT;

--Execute the Transactions from Section 9.2
--Trans 1
INSERT INTO PROJECTIONS VALUES (1, 1, 12, 1, 1, 1);
--Trans 2
INSERT INTO PROJECTIONS VALUES (2, 1, 10, 1, 1, 1);
--Trans 3
INSERT INTO PROJECTIONS VALUES (3, 1, 15, 1, 1, 1);
--Trans 4
INSERT INTO PROJECTIONS VALUES (4, 1, 17, 1, 1, 1);
--Trans 5
INSERT INTO PROJECTIONS VALUES (5, 1, 18, 1, 1, 1);

--For each of the following, 
--change the date in p_audit to reflect date in book
--Trans 6
DELETE FROM PROJECTIONS WHERE PROJECTION_ID = 5;
UPDATE P_AUDIT SET When_Changed = TO_DATE('02/03/1996', 'MM/DD/YYYY')
 WHERE PROJECTION_TYPE = 18 AND 
       When_Changed = (SELECT MAX(When_Changed) from P_Audit WHERE PROJECTION_TYPE = 18);

--Trans 7
UPDATE PROJECTIONS SET PROJECTION_TYPE = 13 WHERE PROJECTION_ID = 2;
UPDATE P_AUDIT SET When_Changed = TO_DATE('03/20/1996','MM/DD/YYYY') 
 WHERE PROJECTION_TYPE = 10 AND 
       When_Changed = (SELECT MAX(When_Changed) from P_Audit WHERE PROJECTION_TYPE = 10);

--Trans 8
UPDATE PROJECTIONS SET PROJECTION_TYPE = 11 WHERE PROJECTION_ID = 3;
UPDATE P_AUDIT SET When_Changed = TO_DATE('05/28/1996','MM/DD/YYYY') 
 WHERE PROJECTION_TYPE = 15 AND 
       When_Changed = (SELECT MAX(When_Changed) from P_Audit WHERE PROJECTION_TYPE = 15);

--Trans 9
UPDATE PROJECTIONS SET PROJECTION_TYPE = 14 WHERE PROJECTION_ID = 2;
UPDATE P_AUDIT SET When_Changed = TO_DATE('06/17/1996','MM/DD/YYYY') 
 WHERE PROJECTION_TYPE = 13 AND 
       When_Changed = (SELECT MAX(When_Changed) from P_Audit WHERE PROJECTION_TYPE = 13);

--Trans 10
DELETE FROM PROJECTIONS WHERE PROJECTION_ID = 4;
UPDATE P_AUDIT SET When_Changed = TO_DATE('07/12/1996','MM/DD/YYYY')
 WHERE PROJECTION_TYPE = 17 AND 
       When_Changed = (SELECT MAX(When_Changed) from P_Audit WHERE PROJECTION_TYPE = 17);
