SQL - TriggersWhich of the following is the correct way to create a row-level AFTER UPDATE trigger on a table named employees?ACREATE TRIGGER trg BEFORE UPDATE ON employees FOR EACH STATEMENT BEGIN -- trigger body END;BCREATE TRIGGER trg AFTER UPDATE ON employees FOR EACH ROW BEGIN -- trigger body END;CCREATE TRIGGER trg AFTER DELETE ON employees FOR EACH ROW BEGIN -- trigger body END;DCREATE TRIGGER trg AFTER UPDATE ON employees BEGIN -- trigger body END;Check Answer
Step-by-Step SolutionSolution:Step 1: Identify trigger timing and eventThe question asks for AFTER UPDATE trigger.Step 2: Identify row-level syntaxRow-level triggers use FOR EACH ROW clause.Step 3: Match syntaxCREATE TRIGGER trg AFTER UPDATE ON employees FOR EACH ROW BEGIN -- trigger body END; correctly uses AFTER UPDATE ON employees FOR EACH ROW.Final Answer:CREATE TRIGGER trg AFTER UPDATE ON employees FOR EACH ROW BEGIN -- trigger body END; -> Option BQuick Check:AFTER UPDATE + FOR EACH ROW required [OK]Quick Trick: Row-level AFTER triggers need FOR EACH ROW [OK]Common Mistakes:Omitting FOR EACH ROW for row-level triggersUsing BEFORE instead of AFTERConfusing event type (UPDATE vs DELETE)
Master "Triggers" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Query Patterns - Conditional aggregation pattern - Quiz 12easy Advanced Query Patterns - Conditional aggregation pattern - Quiz 3easy Advanced Window Functions - Percent of total with window functions - Quiz 10hard Common Table Expressions (CTEs) - Why CTEs are needed - Quiz 9hard Common Table Expressions (CTEs) - Recursive CTE concept - Quiz 13medium Database Design and Normalization - Second Normal Form (2NF) - Quiz 6medium Indexes and Query Performance - How an index works (B-tree mental model) - Quiz 3easy Transactions and Data Integrity - Why transactions are needed - Quiz 11easy Transactions and Data Integrity - Transaction isolation levels - Quiz 14medium Window Functions Fundamentals - Window function vs GROUP BY mental model - Quiz 2easy