Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8226231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:41:39+00:00 2026-06-07T15:41:39+00:00

While creating a blog, I’ve decided that using triggers would be a convenient way

  • 0

While creating a blog, I’ve decided that using triggers would be a convenient way to add and remove posts while maintaining a counter within the category table. Here are my two triggers for incrementing and decrementing the counter in my categories table:

delimiter |
CREATE TRIGGER increment_category_count AFTER INSERT ON posts
  FOR EACH ROW BEGIN
    UPDATE categories SET count = count + 1 WHERE id = NEW.category_id;
  END;
|
delimiter ;

delimiter |
CREATE TRIGGER decrement_category_count AFTER DELETE on posts
  FOR EACH ROW BEGIN
    UPDATE categories SET count = count - 1 WHERE id = OLD.category_id;
  END;
|
delimiter ;

I’m concerned that if something goes wrong while inserting or deleting a post, then my counters would become inaccurate. Is there something in MySQL that would enable me to do a rollback in a trigger if something goes wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:41:40+00:00Added an answer on June 7, 2026 at 3:41 pm

    Any change that is done in a trigger will be rolled back (or committed) with the transaction that fired the trigger (assuming you do use InnoDB for your tables).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while creating a blog i am using the following model class and form .but
While creating JavaScript with ASP.NET MVC I noticed several scope warnings and realized that
While creating an online shop application using play-1.2.4 ,I ran into some problems with
While creating my horizontal menu using the <ul><li>....</li></ul> I came across a few behaviors
I ran into some trouble while creating a C-Extension for ruby that got me
I'm after creating a webpage that includes a blog section and it currently displays
I need to change the default email text that will be sent while creating
I'm currently creating a Rest client for making blog posts much in the spirit
While creating a WCF Rest service, I've noticed that not all the parameters in
While creating classes, I followed OO conventions and declared all class variables before using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.