比赛表 match
match_id mantch_name max_num
1 xxx杯比赛 100
2               AAA杯比赛         200比赛报名表 match_register
register_id match_id user_id
1 1 002报名的最大人数不能超过match.max_num.
我的做法:
在用户报名xxx杯比赛时
select count(*) from match_register where match_id=1
if(count(*)>=match.max_num)
   return报名人数满,
else
   insert into match_register.
集中报名时,报名人数还是会超出max_num。
数据库设计是否合理?怎么保证报名的最大人数不能超过match.max_num?java 数据库数据库java

解决方案 »

  1.   

    insert into match_register.
    return "申请成功!报名是否有效请看通知!";以下是后台单例定时执行
    select count(*) from match_register where match_id=1
    if(count(*)>match.max_num){
       delete match_register where ...;//删除最晚报名的人
       return "报名人数满";//给那个人发消息}