0
To register the matches of a football championship the following tables were defined:
Time (
id int primary key,
nome char(20),
pontos int,
nroVitorias,
golsMarcados int,
golsSofridos int )
Jogo (
idTime1 int,
idTime2 int,
golsTime1 int,
golsTime2,
primary key (idTime1, idTime2) )
The table Team is previously loaded with data id
and nome
of all the teams participating in the championship and with all the
other zeroed values. The table Games is empty.
Write SQL commands to resolve the following requests:
The columns idTime1
and idTme2
must be defined as foreign keys referencing the table Team.
Write the commands for setting these 2 foreign keys so that a team that already has a registered game cannot be deleted and if a team id is changed, their games are preserved.
It is possible for me to create a foreign key from a column in a table (Time), referencing two columns in another table (Games)?
Thank you.
can yes. if you are using phpmyadmim, the own does it very easily.
– Risk
Add what you’ve tried to exercise.
– 8biT
@8bit ALTER TABLE Time ADD CONSTRAINT Timegame FOREIGN KEY (id) REFERENCES Game (idTime1, idTime2);
– user131916
Right, what exactly do you mean by
e se o id de um time for alterado, os seus jogos são preservados.
? Will the Team ID (Primary Key) be changed at some point? How will this be done ?– 8biT