Using CREATE TRIGGER statement you can create a trigger. You have to put the trigger name after the trigger statement.
For example we have two tables i.e. users and userhistory.
users:
userID
firstName
lastName
userhistory:
userID
last_update
Read Also: INSERT … ON DUPLICATE KEY UPDATE
Now we will create a trigger before update users table:
DELIMITER $ CREATE TRIGGER before_user_update BEFORE UPDATE ON users FOR EACH ROW BEGIN INSERT INTO userhistory SET last_update = NOW(), userID = OLD.userID; END$ DELIMITER ;
Whenever user update their information userhistory table also get updated automatically.
Triggers could be defined on the table, schema, view or database with which the event is associated.
Triggers can be written for the following purposes:
Battery coating is the process of applying uniform layers of active materials—such as cathode and…
Let’s face it. Tech buzzwords get thrown around a lot—especially when it comes to how…
In today’s digital world, the boundaries between technology, finance, and innovation are rapidly disappearing. Businesses…
Backyard gatherings like BBQs, family reunions, and garden parties are an exciting way to enjoy…
Marketers are always on the lookout for more effective ways to reach their target audiences.…
Does your phone control your mind more than you control your phone? Modern life exploits…