IT Learning HubIT Learning Hub
WEEK 5 · PRACTICE EXERCISES

Exercises & Answer Key

IT004BTTH5Trigger Exercises

The exercise statement is open to read freely. The answer key and detailed explanations are reserved for students currently enrolled in the IT004 practicum class and require an access code from the instructor.

EXERCISE

Trigger Exercises

Week 5 uses TRIGGER to implement business rules that a regular CHECK cannot handle (comparisons across multiple tables, aggregate calculations...), across both shared schemas, Sales Management and Academic Affairs Management. Full question details are in the attached file below.

Full exercise - Week 5 practice (BTTH5) PDF file · Trigger exercises
Download ↓
This exercise uses the shared Sales Management schema (KHACHHANG, NHANVIEN, SANPHAM, HOADON, CTHD) - see the full attributes, sample data, and database script. View schema ›
And the shared Academic Affairs Management schema (HOCVIEN, LOP, KHOA, MONHOC, DIEUKIEN, GIAOVIEN, GIANGDAY, KETQUATHI) - see the full attributes, sample data, and database script. View schema ›
Submission requirement: Save your work in a single script file named <MSSV>_<HoVaTen>_BTTH5.sql (MSSV is your student ID, HoVaTen is your full name).

Sales Management database (questions 1-4)

  1. A member customer's purchase date (NGHD) must be greater than or equal to their membership registration date (NGDK).
  2. An employee's sale date (NGHD) must be greater than or equal to their hire date.
  3. An invoice's total value is the sum of the line totals (quantity * unit price) of the line items belonging to that invoice.
  4. A customer's sales figure is the sum of the invoice totals that member customer has purchased.

Academic Affairs Management database (questions 1-12)

  1. A class's class monitor must be a member of that class.
  2. A department head must be a teacher belonging to the department and hold the degree "TS" or "PTS".
  3. A student may only take an exam for a subject once their class has finished studying that subject.
  4. In each semester of an academic year, a class may study at most 3 subjects.
  5. A class's enrollment count must equal the number of students belonging to that class.
  6. In the relation DIEUKIEN, the values of MAMH and MAMH_TRUOC within the same tuple may not be identical ("A","A"), and there may also not exist both the tuple ("A","B") and the tuple ("B","A").
  7. Teachers with the same degree, academic rank, and salary coefficient must have the same salary.
  8. A student may only retake an exam (attempt >1) if the score from the previous attempt was below 5.
  9. The exam date of a later attempt must be later than the exam date of the previous attempt (for the same student, same subject).
  10. A student may only take an exam for subjects their class has already finished studying.
  11. When assigning a subject to be taught, the prerequisite order between subjects must be respected (a subject may only be taught after its prerequisite subjects have been completed).
  12. A teacher may only be assigned to teach subjects belonging to the department they are responsible for.

ANSWER

View answer

Protected content

Enter the access code to view the Week 5 answer.

Access code provided by the instructor.