You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+173-3Lines changed: 173 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -269,59 +269,229 @@ COMMIT;
269
269
<br>
270
270
<br>
271
271
272
-
# THIS MARK THE CONCLUSION OF OUR PROJECT
272
+
# **Phase 7: Advanced Database Programming and Auditing**
273
+
274
+
This phase focuses on implementing advanced PL/SQL techniques to enhance the **Course Management System (CMS)**. These features aim to ensure system efficiency, maintain data integrity, and establish robust auditing for improved functionality and security.
275
+
276
+
277
+
## **Problem Statement**
278
+
279
+
The CMS requires advanced programming techniques to address the following challenges:
280
+
1. Enforcing business rules and automating workflows using **triggers**.
281
+
2. Efficient row-by-row data processing with **cursors**.
282
+
3. Improving modularity and reusability with **packages**.
283
+
4. Monitoring and restricting access to sensitive data using **auditing mechanisms**.
284
+
285
+
286
+
### **a) BEFORE Trigger**
287
+
This trigger enforces validation for attendance status before data is inserted into the `ATTENDANCE` table.
288
+
289
+
CREATE OR REPLACE TRIGGER before_attendance_insert
290
+
BEFORE INSERT ON ATTENDANCE
291
+
FOR EACH ROW
292
+
BEGIN
293
+
IF :NEW.Status NOT IN ('Present', 'Absent') THEN
294
+
RAISE_APPLICATION_ERROR(-20001, 'Invalid status. Must be Present or Absent.');
295
+
END IF;
296
+
END;
297
+
/
298
+
299
+
### **b) Compound Trigger**
300
+
This trigger ensures assignment submission deadlines are respected. It also validates that the assignment ID exists.
301
+
302
+
CREATE OR REPLACE TRIGGER submission_deadline
303
+
BEFORE INSERT OR UPDATE ON SUBMISSION
304
+
FOR EACH ROW
305
+
DECLARE
306
+
due_date ASSIGNMENT.Due_Date%TYPE;
307
+
BEGIN
308
+
SELECT Due_Date
309
+
INTO due_date
310
+
FROM ASSIGNMENT
311
+
WHERE Assignment_ID = :NEW.Assignment_ID;
312
+
313
+
IF :NEW.Submission_Date > due_date THEN
314
+
RAISE_APPLICATION_ERROR(-20002, 'Submission past the due date.');
315
+
END IF;
316
+
EXCEPTION
317
+
WHEN NO_DATA_FOUND THEN
318
+
RAISE_APPLICATION_ERROR(-20003, 'Assignment ID not found.');
319
+
END;
320
+
/
321
+
322
+
## **2. Cursor Usage**
323
+
324
+
This implementation calculates the average grade for each student using explicit cursors.
325
+
326
+
DECLARE
327
+
CURSOR student_grades IS
328
+
SELECT g.Student_ID, s.Name, AVG(g.Grade_Value) AS Avg_Grade
329
+
FROM GRADE g
330
+
JOIN STUDENT s ON g.Student_ID = s.Student_ID
331
+
GROUP BY g.Student_ID, s.Name;
332
+
333
+
v_student_id STUDENT.Student_ID%TYPE;
334
+
v_student_name STUDENT.Name%TYPE;
335
+
v_avg_grade NUMBER;
336
+
BEGIN
337
+
OPEN student_grades;
338
+
LOOP
339
+
FETCH student_grades INTO v_student_id, v_student_name, v_avg_grade;
0 commit comments