저는 약간의 웹 기반 게임을 만들고 있으며 SQL 데이터베이스의 기본 데이터의 무결성을 검사하는 로직을 어디에 둘 것인지 결정해야합니다.포인트 시스템 관계를 유지 관리하기위한 db의 논리는 무엇입니까?
각 사용자는 자신에게 할당 된 점수를 추적하고 점수는 다양한 작업으로 부여됩니다. 개인별 보상 수준이 시간에 따라 변동하기 때문에 각 작업 트랜잭션에 대한 기록을 보관하여 반복되지 않도록하고 완료 시점의 작업 값을 추적합니다.
내 스키마는 지금까지 다음과 같습니다
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)
);
는 그래서,
player.player_Points
이
task_list
에서 자신의 모든 누적 작업 점의 총 수 있어야합니다.
이제 로직을 어디에 적용해야합니까?
전체 점수를 알고 싶을 때마다
player.player_Points
을 삭제하고 쿼리를 수행해야합니까? 내가 게임의 과정에서 많은 질문을 할 것이므로 낭비되는 것 같습니다.
task_list
에 트리거를 넣으면 자동으로 player.player_Points
가 업데이트됩니까? 데이터베이스에 너무 많은 논리가 있고 응용 프로그램에서이 관계를 유지해야합니까?
감사합니다.