MySQL Triggers Tutorial: Before & After Events 📋

Learn how to use MySQL triggers for BEFORE UPDATE, INSERT, and AFTER DELETE with step-by-step setup and examples.

MySQL Triggers Tutorial: Before & After Events 📋
Bro Code
199.3K views • Nov 22, 2022
MySQL Triggers Tutorial: Before & After Events 📋

About this video

#MySQL #tutorial #course

00:00:00 intro
00:00:33 setup part 1
00:02:01 BEFORE UPDATE
00:05:45 BEFORE INSERT
00:08:14 setup part 2
00:10:45 AFTER DELETE
00:12:37 AFTER INSERT
00:14:34 AFTER UPDATE
00:16:25 conclusion

CREATE TRIGGER before_hourly_pay_update
BEFORE UPDATE ON employees
FOR EACH ROW
SET NEW.salary = (NEW.hourly_pay * 2080);

CREATE TRIGGER before_hourly_pay_insert
BEFORE INSERT ON employees
FOR EACH ROW
SET NEW.salary = (NEW.hourly_pay * 2080);

CREATE TRIGGER after_salary_delete
AFTER DELETE ON employees
FOR EACH ROW
UPDATE expenses
SET expense_total = expense_total - OLD.salary
WHERE expense_name = "salaries";

CREATE TRIGGER after_salary_insert
AFTER INSERT ON employees
FOR EACH ROW
UPDATE expenses
SET expense_total = expense_total + NEW.salary
WHERE expense_name = "salaries";

CREATE TRIGGER after_salary_update
AFTER UPDATE ON employees
FOR EACH ROW
UPDATE expenses
SET expense_total = expense_total + (NEW.salary - OLD.salary)
WHERE expense_name = "salaries";

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

199.3K

Likes

4.9K

Duration

16:50

Published

Nov 22, 2022

User Reviews

4.7
(39)
Rate:

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.

Trending Now