2013-07-07 41 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