CREATE TRIGGER  Max_EnrollCheck
   BEFORE INSERT ON Transcript
         REFERENCING NEW AS N   --row to be added
   FOR EACH ROW
   WHEN
   ((SELECT  COUNT (T.StudId) FROM Transcript T
       WHERE  T.CrsCode = N.CrsCode 
                      AND T.Semester = N.Semester) 
    >=
    (SELECT C.MaxEnroll FROM Course C
       WHERE C.CrsCode = N.CrsCode ))
   ABORT TRANSACTION;
.
RUN;

