From the course: Intermediate SQL: Data Reporting and Analysis

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Problems with foreign key constraints

Problems with foreign key constraints - SQL Tutorial

From the course: Intermediate SQL: Data Reporting and Analysis

Problems with foreign key constraints

- [Narrator] Deleting a single row in one table can trigger the unintended deletion of millions of rows across multiple other tables depending on your settings. Here we look at how to work out what will happen and how to change it before you hit delete. Usually when you try to delete data, you are prevented because of a constraint. We saw earlier that we could not easily delete a row from the category table, for example. Let's look at the film category table now and the structure tab. Need to click relation view, top left, it's not obvious and these are your foreign key constraints, as it says, top left, we've seen them once before. So film_id and category_id are both foreign keys within the film category table. And this table shows the behaviors you can expect if you were to delete a row from the category table. On each of these two rows, it says on delete restrict, on update cascade. So let's work this out. If we click…

Contents