From the course: MySQL Advanced Topics (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Deleting and changing foreign keys

Deleting and changing foreign keys - MySQL Tutorial

From the course: MySQL Advanced Topics (2019)

Deleting and changing foreign keys

- [Instructor] In order to change a foreign key constraint you must first delete it. This is relatively simple to do. If you've been following along, the foreign key constraint and widget sale is currently set to cascade and the tables have been updated like this. Go ahead and execute these commands. And you see that our parent table which the customer has these IDs one, three and nine. And our child table, widget sale has the corresponding columns here in the customer ID column. So if your database is not in this state then please follow the previous lesson to get to this point. So now that we have the foreign key constraint defined it's currently set to cascade and we're going to change it to restrict but just to show that it's in cascade, I can set that ID back and select these tables again. And you notice that it's now back to one, two and three. And that's the same state in both the parent and the child tables. So…

Contents