Instruction
Just as we expected – we failed. Why is that so? Because when we write REFERENCES... after FOREIGN KEY (...):
FOREIGN KEY (...) REFERENCES ...we actually mean:
REFERENCES ... ON UPDATE RESTRICT ON DELETE RESTRICTIn other words, the database won't allow us to update or delete a primary key that's linked to another table via a foreign key.
There are, however, other options we can use instead of RESTRICT:
CASCADE– When the referenced row is deleted or updated, the respective rows of the referencing table will be deleted or updated.NO ACTION– Means "Do nothing to the referenced row". (In our database, this is the same asRESTRICT; in some databases,NO ACTIONis slightly different thanRESTRICT).SET NULL– The values of the affected rows are set toNULL.SET DEFAULT– The values of the affected rows are set to their default values.
Exercise
Run the template code, which creates a new version of the project table – this time with CASCADE. Take a close look at how it's done.



