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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:43:53+00:00 2026-05-14T18:43:53+00:00

I’m making a little web based game and need to determine where to put

  • 0

I’m making a little web based game and need to determine where to put logic that checks the integrity of some underlying data in the sql database.

Each user keeps track of points assigned to him, and points are awarded by various tasks. I keep a record of each task transaction to make sure they’re not repeated, and to keep track of the value of the task at the time of completion, since an individual award level my fluctuate over time.

My schema looks like this so far:

create table player (
  player_ID           serial primary key,
  player_Points       int not null default 0
);

create table task (
  task_ID             serial primary key,
  task_PointsAwarded  int not null
);

create table task_list (
  player_ID           int references player(player_ID),
  task_ID             int references task(task_ID),
  when_completed      timestamp default current_timestamp,
  point_value         int not null,  --not fk because task value may change later
  constraint pk_player_task_id primary key (player_ID, task_ID)
);

So, the player.player_Points should be the total of all his cumulative task points in the task_list.
Now where do I put the logic to enforce this?
Should I do away with player.player_Points altogether and do queries every time I want to know the total score? Which seems wasteful since I’ll be doing that query a lot over the course of a game.

Or, put a trigger in the task_list that automatically updates the player.player_Points? Is that too much logic to have in the database and should just maintain this relationship in the application?

Thanks.

  • 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-05-14T18:43:54+00:00Added an answer on May 14, 2026 at 6:43 pm

    From a relational standpoint you’d want to do away with player.player_Points altogether so that you don’t have to worry about the integrity of the data. If this is too much of a performance burden then you could denormalize it as you have, but I’d do some stress testing on the app to make sure this is the case, no need to prematurely optimize and its a pretty simple query to get the value (not just logically but from a database workload perspective as well).

    Personally even if you go with the denormalized route I would not use a trigger, but that’s just a personal bias, you certainly could go that route. I’d probably just set up some integration tests to make sure everything is updating properly whenever you perform inserts/updates/deletes, and possibly save a query that you can run periodically if you suspect there is a problem.

    I’d also consider adding a daterange on task so that you don’t have to store the points_value in the task_list.

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

Sidebar

Related Questions

No related questions found

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.