Database Management MySQL Subjective
Oct 01, 2025

What are triggers in MySQL? Provide an example.

Detailed Explanation

Triggers are special stored procedures that automatically execute in response to database events.

Types:
• BEFORE INSERT/UPDATE/DELETE
• AFTER INSERT/UPDATE/DELETE

Example:
CREATE TRIGGER update_modified_time
BEFORE UPDATE ON users
FOR EACH ROW
BEGIN
  SET NEW.updated_at = NOW();
END;

-- Automatically updates timestamp on every user update

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback