
/* Code Fragment 9.17 Triggers for maintaining the P_TT table. */

CREATE TRIGGER DELETE_P_TT
ON P_TT_CURRENT
FOR DELETE
AS
BEGIN
	INSERT P_TT_PAST
	SELECT 	P.PROJECTION_ID, P.PROJECTION_NAME, P.PROJECTION_TYPE, P.SPHEROID_CODE,
		P.PROJECTION_UOM,P.ZONE_CODE, P.Start_Date, GETDATE()
	FROM P_TT_CURRENT AS P, Deleted
	WHERE P.PROJECTION_ID <> Deleted.PROJECTION_ID

RAISERROR('DELETE TRIGGER LAUNCHED',1,2)
END

/*
CREATE TRIGGER UPDATE_P_TT
ON P_TT_CURRENT
FOR UPDATE
AS
BEGIN
	INSERT P_TT_PAST
	SELECT 	P.PROJECTION_ID, P.PROJECTION_NAME, P.PROJECTION_TYPE, P.SPHEROID_CODE,
		P.PROJECTION_UOM,P.ZONE_CODE, P.Start_Date, GETDATE()
	FROM P_TT_CURRENT AS P, Deleted
	WHERE P.PROJECTION_ID = Deleted.PROJECTION_ID

	UPDATE P_TT_CURRENT
	SET Start_Date = GETDATE()
	FROM Deleted
	WHERE P_TT_CURRENT.PROJECTION_ID = Deleted.PROJECTION_ID
END
*/
