0
0
SQLquery~20 mins

Trigger performance considerations in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Trigger Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Impact of complex logic inside triggers

What is the main performance concern when a trigger contains complex logic that runs on every row affected by a data modification?

AThe trigger may cause significant slowdowns because it executes repeatedly for each row, increasing transaction time.
BThe trigger will only run once per transaction, so complex logic has minimal impact.
CTriggers do not affect performance because they run asynchronously after the transaction commits.
DComplex logic inside triggers improves performance by optimizing data changes automatically.
Attempts:
2 left
💡 Hint

Think about how often the trigger code runs when many rows are changed.

query_result
intermediate
2:00remaining
Output rows affected by trigger with row-level execution

Given a table orders with 3 rows updated in a single statement, and a row-level trigger that inserts a log entry per updated row, how many rows will be inserted into the log table?

SQL
CREATE TRIGGER log_order_update AFTER UPDATE ON orders FOR EACH ROW INSERT INTO order_log(order_id, action) VALUES (NEW.id, 'updated');

UPDATE orders SET status = 'shipped' WHERE status = 'processing';
A1 row will be inserted into <code>order_log</code>.
B3 rows will be inserted into <code>order_log</code>.
CNo rows will be inserted because triggers do not run on UPDATE.
DThe number of rows inserted depends on the number of columns updated.
Attempts:
2 left
💡 Hint

Consider how row-level triggers behave with multiple rows affected.

📝 Syntax
advanced
2:00remaining
Identifying inefficient trigger design

Which trigger design below is likely to cause the worst performance impact on bulk inserts?

AA trigger that only logs the number of rows inserted after the statement completes.
BA statement-level trigger that runs once after all rows are inserted.
CA trigger that disables indexes before insert and rebuilds them after.
DA row-level trigger that performs a complex SELECT query for each inserted row.
Attempts:
2 left
💡 Hint

Think about how often the trigger code runs and what it does each time.

🔧 Debug
advanced
2:00remaining
Diagnosing trigger-induced slow query

A trigger on the employees table causes an UPDATE statement to run very slowly. The trigger updates a departments table for each employee updated. What is the likely cause?

AThe trigger runs an UPDATE on <code>departments</code> for each employee row, causing many repeated updates and locking issues.
BThe trigger disables foreign keys, causing data inconsistency and slow queries.
CThe trigger uses a temporary table which is not indexed, causing slow lookups.
DThe trigger is a statement-level trigger, so it runs only once and cannot cause slowdowns.
Attempts:
2 left
💡 Hint

Consider how triggers that modify other tables per row can affect performance.

🧠 Conceptual
expert
2:00remaining
Best practice to optimize trigger performance on bulk operations

Which approach is best to optimize trigger performance when handling bulk data modifications?

AAvoid using triggers altogether and rely on client-side code for data integrity.
BDisable triggers during bulk operations and re-enable them afterward without any data validation.
CUse statement-level triggers that process all affected rows in a single operation instead of row-level triggers.
DUse row-level triggers with complex logic to handle each row individually for accuracy.
Attempts:
2 left
💡 Hint

Think about minimizing repeated executions during bulk changes.