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 8811917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:28:49+00:00 2026-06-14T03:28:49+00:00

When my users_reputation points table gets updated (insert), I want to take a new

  • 0

When my users_reputation points table gets updated (insert), I want to take a new count (SUM) of this user’s points and update a total_rep column in the users table.

This is what I came up with but keep getting syntax errors. I would greatly appreciate if somebody could point out my mistakes.

CREATE TRIGGER after_insert_rep_points AFTER INSERT ON users_reputation
FOR EACH ROW
BEGIN
DECLARE new_total INT(10);
SELECT SUM(rep_points) INTO new_total FROM users_reputation
WHERE user_id = NEW.user_id;
UPDATE users SET rep_total = new_total WHERE user_id = NEW.user_id;
END

These are my table examples for reference:

USERS:

  user_id    |  first_name    |  total_rep
-------------+----------------+--------------
  10001      |  Jim           |  17
  10002      |  Bob           |  5

USERS_REPUTATION:

  user_id  |  rep_task                     |  rep_points  |  rep_date
-----------+-------------------------------+--------------+-----------------------
  10001    |  Commented on article         |  5           |  2012-11-12 08:40:32
  10001    |  Read an article              |  2           |  2012-06-12 12:32:01
  10001    |  Shared an article            |  10          |  2012-06-04 17:39:44
  10001    |  Read an article              |  2           |  2012-05-19 01:04:11
  10002    |  Commented on article         |  5           |  2012-06-17 09:34:21
  • 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-14T03:28:50+00:00Added an answer on June 14, 2026 at 3:28 am

    You need to add a delimiter change at the beginning.

    delimiter |
    
    CREATE TRIGGER after_insert_rep_points AFTER INSERT ON users_reputation
    ...
    END
    
    |
    delimiter ;
    

    The delimiter signals the DB engine the end of your statement. Normally it is ;. But that would end the stored procedure at the first ;. And its definition would be incomplete.

    You can change the delimiter and add it to the end of your procedure. After that change the delimiter back to ;

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

Sidebar

Related Questions

I have a user a object that looks like this. $user = new User();
I have the following situation. We want an reputation table to evaluate Users And
I'm building an iPhone app that, among other things, allows the user to take
Trying to make a spinner that pops up a new little screen the user
This MySQL will increment a user's reputation by 5 when an upvote is submitted.
A very simple feature with complex inside. I want when a user input tag,
I have an users table where I store user info along with a reputation
In stackoverflow, when we hover on a user's reputation we see a text. I
I'm entirely new at SQL, but let's say that on the StackExchange Data Explorer
I have a simpe table: Users UserID Guid doesnt allow null Avatar image allows

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.