Which is the syntax for enforcing the rule of deleting the dependent Foreign Key values on the deletion of a Primary Key?

  1. ON DELETE SET NULL

  2. ON DELETE CASCADE

  3. ON DELETE DELETE

  4. ON DELETE RESTRICT


Correct Option: B
Explanation:

To answer this question, the user needs to have knowledge of database management systems and the concept of Foreign Keys.

When a Foreign Key references a Primary Key in another table, there is a possibility that the referenced record(s) may be deleted. In such cases, four actions can be taken: SET NULL, CASCADE, DELETE, or RESTRICT.

  • ON DELETE SET NULL: This option sets the Foreign Key value to NULL when the referenced record(s) are deleted. This may lead to data integrity issues and is not ideal in most cases.

  • ON DELETE CASCADE: This option deletes all the dependent rows in the child table when the referenced rows in the parent table are deleted. This is usually the preferred option when the child rows are no longer relevant without the parent rows.

  • ON DELETE DELETE: This syntax does not exist, and hence, it is incorrect.

  • ON DELETE RESTRICT: This option prevents the deletion of the referenced rows in the parent table when there are dependent rows in the child table. This is useful when the data in the child table is still relevant and associated with the data in the parent table.

Therefore, the correct answer is:

The Answer is: B. ON DELETE CASCADE

Find more quizzes: