コンペティション、ユーザー、プロジェクト リーダーのテーブルが既にあるとします。これは次のようになります。
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,
...
);
そして、これでうまくいくはずです。仕様に合わせてスキーマを変更してください...