0
0
SQLquery~5 mins

DELETE trigger in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a DELETE trigger in SQL?
A DELETE trigger is a special kind of stored procedure that automatically runs when a DELETE operation happens on a table. It lets you react to row deletions, like logging or preventing the delete.
Click to reveal answer
beginner
When does a DELETE trigger execute?
A DELETE trigger executes immediately before or after a DELETE statement removes rows from a table, depending on whether it is defined as BEFORE DELETE or AFTER DELETE.
Click to reveal answer
intermediate
What is the difference between BEFORE DELETE and AFTER DELETE triggers?
BEFORE DELETE triggers run before the rows are deleted, allowing you to check or modify data. AFTER DELETE triggers run after the rows are deleted, useful for actions like logging the deletion.
Click to reveal answer
intermediate
How can you access the deleted rows inside a DELETE trigger?
Inside a DELETE trigger, you can access the deleted rows using the special table called OLD (in some SQL dialects) or DELETED (in others), which holds the data of the rows being deleted.
Click to reveal answer
beginner
Why would you use a DELETE trigger in a database?
You use a DELETE trigger to automatically perform tasks like auditing deletions, enforcing business rules, preventing accidental deletes, or cleaning up related data when rows are deleted.
Click to reveal answer
What does a DELETE trigger do?
ARuns automatically when rows are deleted from a table
BRuns when rows are inserted into a table
CRuns when rows are updated in a table
DDeletes a table automatically
Which special table holds the deleted rows inside a DELETE trigger?
AOLD
BNEW
CCURRENT
DINSERTED
When does an AFTER DELETE trigger run?
ABefore rows are deleted
BBefore rows are inserted
CAfter rows are updated
DAfter rows are deleted
Which of these is NOT a common use of DELETE triggers?
ALogging deleted rows
BPreventing accidental deletes
CAutomatically inserting new rows
DCleaning up related data
Can a DELETE trigger modify the data being deleted before it happens?
ANo, only INSERT triggers can modify data
BYes, if it is a BEFORE DELETE trigger
CYes, but only AFTER DELETE triggers
DNo, triggers cannot modify data
Explain what a DELETE trigger is and when it runs.
Think about what happens when you remove rows from a table.
You got /3 concepts.
    Describe two practical uses of DELETE triggers in a database.
    Why would you want to react automatically when data is deleted?
    You got /4 concepts.