Tag Info

New answers tagged

6

It's a question of timing. Consider deleting StudentID #1: The row is deleted from the Student table The cascade delete removes corresponding rows from Enrollment The foreign key relationship GPA -> Student is checked The trigger fires, calling MergeGPA At this point, MergeGPA checks to see if there is an entry for Student #1 in the GPA table. There is ...


-1

Without reading all, just from the diagram: You have either an entry in Enrollment or one in GPA pointing to the Student you want to delete. The entries with the foreign keys need to be deleted first (or the keys set to null, but that is bad practice) before you can delete the Student entry. Also some databases have ON DELETE CASCADE, which will delete any ...


1

It is actually possible to do this neatly without using triggers if you are using InnoDB. Create another table with just one column. That column should have a foreign key (hence the innodb requirement in this solution) that points to the immutable column of the original table in question. Put a restriction like "ON UPDATE RESTRICT". In summary: CREATE ...



Top 50 recent answers are included