Simple Record Database

(extracted from the paper of Transaction Logic Programming)

Suppose a university has a database of students, courses, and professors, the database includes the following four base relations:

Using the following transaction program can ensure database consistency when a student drops a course or a professor is relieved from teaching a course.
declare takes/3.
declare enrolled/2 key 1.
declare instructs/3.
declare load/2 key 1.

drop(Stud,Crs,Sec) <- destroy(takes(Stud,Crs,Sec) sc decr_enrolled(Crs).
relieve(Prof,Crs,Sec) <- destroy(instructs(Prf,Crs,Sec)) sc decr_load(Prof).
decr_encrolled(Crs) <- enrolled(Crs,N) sc N1 is N-1 sc set(enrolled(Crs,N1)).
decr_load(Prof) <- load(Prof,N) sc N1 is N-1 sc set(load(Prof,N1)).

When a student drops a course, the program decrements the enrollment total and when a professor is relieved from teaching a course, the professor's course load is decremented.

Back to the main page