mysql - should the following sql query data normalization work? -
create table if not exists `mydb`.`matches` ( `idmatch` int not null , `idchampionship` int not null , `idwinningteam` int not null , `idwloosingteam` int not null , `date` timestamp null default null , `goalswinningteam` int null default -1 , `goalsloosingteam` int null default -1 , `played` char null default 'y' , primary key (`idmatch`) , index `id_team_x_champ` (`idmatch` asc) , constraint `id_team_x_champ` foreign key (`idchampionship` , `idmatch` ) references `mydb`.`teams_per_championship` (`idchampionship` , `idteam` ) on delete no action on update no action) engine = innodb;
i'm trying make matches table , i'm not sure how set winning , losing team,
both idteam (can use same foreign key both?) have team table championship
table , teams_per_champsionship table (for indexing).
schema available
thanks much
an example schema:
team table ---------- teamid pk rest of team information championship table ------------------ champid pk rest of championship info match table ----------- matchid pk winningteamid fk losingteamid fk rest of match info champmatchtable --------------- champid fk (dups) machid fk
or
you put champid in match table , not have champmatchtable.
original answer below
yes can not use same key both. both keys same table different (since each team different.)
not clear idchamionship key points to. table describes event has matches?
Comments
Post a Comment