
/* Code Fragment 6.14 Bob was assigned the position of Associate Director of the Computer center for 1997, alse ensuring referential integrity. */

INSERT INCUMBENTS
SELECT '111-22-3333','999071', '1997-01-01', '1998-01-01'
FROM INCUMBENTS
WHERE EXISTS (	SELECT *
		FROM INCUMBENTS AS I2
		WHERE I2.SSN = '111-22-3333'
		AND I2.START_DATE < '1998-01-01'
		AND I2.END_DATE > '1997-01-01')
AND EXISTS (	SELECT *
		FROM POSITIONS AS P
		WHERE P.PCN = '999071'
		AND P.START_DATE <= '1997-01-01'
		AND P.END_DATE > '1997-01-01')
AND EXISTS (	SELECT *
		FROM POSITIONS AS P
		WHERE P.PCN = '999071'
		AND P.START_DATE < '1998-01-01'
		AND P.END_DATE >= '1998-01-01')
AND NOT EXISTS (SELECT *
		FROM POSITIONS AS P
		WHERE P.PCN = '999071'
		AND P.END_DATE > '1997-01-01'
		AND P.END_DATE < '1998-01-01'
		AND NOT EXISTS (SELECT *
				FROM POSITIONS AS P2
				WHERE P2.PCN = '999071'
				AND P2.START_DATE <= P.END_DATE
				AND P.END_DATE < P2.END_DATE))



