On Delete Cascade
I am reading through on page 572 of your book and I was wondering could not this be better handled if the backend of the database handled this when the database was set up with the standard triggers of on delete cascade? I have always been told that handling issues like this at the database level rather than at the front end is or has been always the best way to go.
CREATE TABLE Courses (
CourseID int NOT NULL PRIMARY KEY,
Course VARCHAR(63) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
);
CREATE TABLE ImarBookCourses (
EntryID int NOT NULL PRIMARY KEY,
BookID int NOT NULL,
Course CHAR(4) NOT NULL,
CourseNum CHAR(3) NOT NULL,
CourseSec CHAR(1) NOT NULL
);
and I establish a foreign key relationship between the two, like this:
ALTER TABLE ImarBookCourses
ADD FOREIGN KEY (Course)
REFERENCES Courses(Code)
ON DELETE CASCADE;
I mean I am just saying. That is all. Kind of different way to approach this matter is it not?
|