I have created a database which manages registrations for training
courses. There is a limit of 20 registrations per course. I would
like a 'pop up' message to appear if the user tries to register a
person for a course which already has 20 people registered.
How do I do this? Is this when DataValidationis used?
Approach 1: use referential integrity:
CREATE TABLE Students (
student_ID INTEGER NOT NULL UNIQUE
)
;
CREATE TABLE Classes (
class_ID INTEGER NOT NULL UNIQUE,
seating_capacity INTEGER NOT NULL,
CHECK (seating_capacity > 0),
UNIQUE (seating_capacity, class_ID)
)
;
CREATE TABLE Enrolment (
class_ID INTEGER NOT NULL,
seating_capacity INTEGER NOT NULL,
FOREIGN KEY (seating_capacity, class_ID)
REFERENCES Classes (seating_capacity, class_ID),
student_ID INTEGER NOT NULL
REFERENCES Students (student_ID),
UNIQUE (class_ID, student_ID),
seat_number INTEGER NOT NULL,
UNIQUE (class_ID, seat_number),
CONSTRAINT row_level_CHECK_constraint
CHECK (seat_number <= seating_capacity)
)
;
The pros include ease of implementation in Access because the row-level
CHECK constraint can be replaced by a record-level Validation Rule. The
cons include the otherwise-redundant repeating seating_capacity on each
row and the burdensome need to maintain a sequence for seat_number...
Approach 2: 'hide' the need for both the repeating seating_capacity and
the sequence of seat numbers in a table-level CHECK constraint:
CREATE TABLE Enrolment (
class_ID INTEGER NOT NULL
REFERENCES Classes (class_ID),
student_ID INTEGER NOT NULL
REFERENCES Students (student_ID),
UNIQUE (class_ID, student_ID),
CONSTRAINT table_level_CHECK_constraint
CHECK ((
SELECT C1.seating_capacity
FROM Classes AS C1
WHERE Enrolment.class_ID = C1.class_ID
) >= (
SELECT COUNT(*)
FROM Enrolment AS E1
WHERE Enrolment.class_ID = E1.class_ID)
)
)
;
http://groups.google.com/group/micr...c10b79f28f/1d4430dc8b50ba8f?#1d4430dc8b50ba8f
Jamie.
--