Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Database Systems - Foreign Key ON DELETE and ON UPDATE Actions
Play lesson

Database Systems with SQL - Full Course - Database Systems - Foreign Key ON DELETE and ON UPDATE Actions

5.0 (0)
6 learners

What you'll learn

This course includes

  • 4.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

You can provide actions on the foreign key with keywords ON DELEE or ON UPDATE. Do not hesitate to put constraints on the database. You want to make sure you have a consistent database, especially if you have several apps using it. The actions that you can specify for a foreign key are: ON DELETE – responds when you try to delete a primary key that is used as a foreign key in another table ON UPDATE – responds when you try to update a primary key that is used as a foreign key in another table The ON DELETE or ON UPDATE actions have a few responses: RESTRICT – Restrict is the default action (if none is specified), and it will reject any update, insert, or delete if it violates the referential integrity. SET DEFAULT - sets invalid foreign keys to a default primary key value. SET NULL - sets an invalid foreign key value to NULL. CASCADE – will make all the same primary key changes to the foreign keys. If you delete or update a primary key then the rows containing matching foreign keys are also deleted or updated to the new value. For example, DeanID is a foreign key that references the Dean ID column. ON DELETE CASCADE causes the database to delete the row with DeanID 123 from the Department table when the dean with ID 123 is deleted from the Dean table ON UPDATE SET NULL causes the database to set DeanID 456 to NULL when the Dean with ID 456 is changed to 789. Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere