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 to make a matches table and I'm not sure how to set winning and losing team,
both by idTeam (can I use same foreign key for both?) I have a Team table a Championship
table and teams_per_champsionship table (for indexing).