0
0
SQLquery~5 mins

CASCADE delete preview in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does CASCADE DELETE do in a database?
It automatically deletes all related rows in child tables when a row in the parent table is deleted.
Click to reveal answer
beginner
Why is CASCADE DELETE useful?
It helps keep data consistent by removing dependent records without needing extra queries.
Click to reveal answer
beginner
What happens if you delete a parent row without CASCADE DELETE set on its foreign keys?
The database will prevent the deletion if child rows exist, to avoid orphaned data.
Click to reveal answer
intermediate
How can you preview which rows will be deleted by a CASCADE DELETE?
By running SELECT queries on child tables filtering by the parent row's key before deleting.
Click to reveal answer
intermediate
Write a simple SQL command to create a foreign key with CASCADE DELETE.
ALTER TABLE child_table ADD CONSTRAINT fk_name FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE CASCADE;
Click to reveal answer
What does ON DELETE CASCADE do in a foreign key constraint?
ADeletes child rows automatically when parent row is deleted
BPrevents deletion of parent rows if child rows exist
CDeletes parent rows automatically when child row is deleted
DDoes nothing on delete
If you want to check which child rows will be deleted by a CASCADE DELETE, what should you do?
ADisable foreign key constraints
BDelete the parent row directly
CDrop the child tables
DRun SELECT queries on child tables filtering by parent key
What happens if you delete a parent row without ON DELETE CASCADE and child rows exist?
ADeletion fails due to foreign key constraint
BParent row is updated instead
CChild rows are deleted automatically
DDeletion succeeds and child rows remain
Which SQL clause defines CASCADE DELETE behavior?
AON UPDATE CASCADE
BON DELETE CASCADE
CON DELETE SET NULL
DON DELETE RESTRICT
Why should you preview CASCADE deletes before running them?
ATo disable foreign keys
BTo speed up the deletion
CTo avoid accidentally deleting important related data
DTo create backups automatically
Explain in your own words what CASCADE DELETE does and why it is important.
Think about what happens to connected data when you remove a main record.
You got /3 concepts.
    Describe how you would preview the rows affected by a CASCADE DELETE before actually deleting.
    Imagine checking what will be lost before pressing delete.
    You got /3 concepts.