2013-07-07 40 views
-1

目前正在开展一项让团队领导者创建“比赛”的项目 - 邀请参加比赛的员工。这部分项目已经完成。我目前正在为“创造竞争”的一部分而努力。 *每个竞赛中,用户可以注册3种活动类型(A型,B型和C型)的结果。每种类型都有不同的权重 - 即A型是最有价值的活动,并且从而为用户注册更多积分数据库设计帮助(活动类型和积分权重)

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

非常感谢提前。

回答

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, 
... 
); 

加入的一切,这应该做的伎俩,现在改变模式,以符合您的规范...

+0

明智的答案。非常感谢。我确实已经有用户,团队领导和比赛 - 这只是挑战类型/权重,但我认为你已经清除了 - 现在无论如何! – JP89

+0

现在不要忘了投票答案,并将其标记为正确的答案:) –

+0

当然:)将确保我回来了一些进展为雅! – JP89