-1

目前正在从事一个让团队领导者创建“比赛”的项目——邀请他们的员工参加比赛。这部分项目已经完成。我目前正在努力解决“创造竞争”部分的一个方面。

总结: *在每场比赛中,用户可以注册 3 种活动类型(A 类、B 类和 C 类)的结果。*每种类型具有不同的权重 - 即 A 类是最有价值的活动,因此为用户。

我的问题是,我应该如何处理这些类型和数据库中的权重。管理员将能够为比赛选择自己的类型和权重 - 当他们构建它们时。

首先十分感谢。

4

1 回答 1

0

假设您已经有比赛、用户和项目负责人表,可能是这样的:

create table users
(user_id int,
constraint pk_users primary key (user_id)
...
);

create table project_leaders
( leader_id int,
constraint pk_leader primary key (leader_id),
user_id int,
constraint fk_leaders foreign key (user_id)
...
);

create table competitions
(competition_id int,
constraint pk_competitions primary key (competition_id),
competition_name varchar(128),
creator_id int,
constraint fk_competition_creator foreign key (creator_id) references project_leaders(leader_id),
created_at datetime,
...
);

现在你需要一个类型和重量的表格......

create table types
(type_id in,
constraint pk_types primary key (type_id),
type_name varchar (128),
...
);

create table weights
(weight_id in,
constraint pk_weight primary key (weight_id),
weight_value int,
...
);


create table types_weights
(type_weight_id int,
constraint pk_types_weights primary key (type_id_weight),
type_id int,
weight_id int,
foreign key fk_types_weights_type foreign key type_id references types (type_id),
foreign key fk_types_weights_weigh foreign key weight_id references (weight_id),
creator_id int,
competition_id,
constraint fk_types_weights_creator foreign key (creator_id) references project_leaders(leader_id),
constraint fk_types_weights_competition foreign key (competition_id) references competitions(competition_id),
created_at datetime,
...
);

现在你需要一个表来加入关系模型中的所有内容

create table competition_participants
(competition_id int,
user_id int,
type_weight_id,
constraint pk_competition_participants primary key (competition_id, user_id, type_weight_id),
constraint fk_competition_participants_competition foreign key (competition_id) references competitions (competition_id),
constraint fk_competition_participants_users foreign key (user_id) references users(user_id),
constraint fk_competiton_participants_types_weights (type_weight_id) references types_weights (type_weight_id), 
created_at datetime,
...
);

这应该可以解决问题,现在更改架构以满足您的规范......

于 2013-07-07T09:35:21.403 回答