Publishing System Settings Logout Login Register
MySQL Triggers - Automating Your Way To Happiness
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on November 24th, 2010
2098 views
MySQL

Addressing The Issue

Our scenario has an issue that would soon become apparent once we began writing code. That is, it's a pain to have to take care of two separate tables when dealing with the comments system. Every single time a new comment is created the user table needs to be updated. And every time a comment is deleted, the same thing has to occur.

Chances are this action would take the form of a method or function in your code, which you'd have to call every time you did an INSERT or DELETE. What if you or someone you're working with forgets to call this update method? Humans are error prone and it's not entirely out of the question that this mistake would be made. So let's solve it.

The solution: takes form of triggers. A trigger is a stored routine, not unlike procedures or functions. But unlike procedures and functions, a trigger is called automatically. When it's called depends on how you configure it. But you may configure a trigger to activate on any of the three following actions: INSERTUPDATE and DELETE.

Triggers are table-specific. When writing a trigger you will declare the action that activates it (any of the three above) and the table on which that action needs to occur. Triggers may be used for any number of things, but they are commonly employed along side procedures and functions.
Next Page
Pages: 1 2 3 4 5
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Bobby Hensley

I'm Bobby Hensley, a 21 year old software engineer from the United States. My primary focuses are C++, Ruby and PHP.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top