I think it would be nicer to add in the second table tbl_games two fields: id_time1 and id_tim2 As foreign keys, imagine that there comes a point of your project that you want to pull information from each team in the game, with the name right? Yes, but depending on who you fill in, you end up with the same names or sla, with the id that wouldn’t happen. As @Luis Felipe said, so you have the information of all 2 teams at any time without needing much effort, just make a INNER JOIN
:
SELECT * FROM `tbl_jogos` AS jogo INNER JOIN `tbl_time` AS time ON jogo.id_time_1 = time.id_Times WHERE jogo.id_Jogos = 1
In this query you get all the information from Team 1 and of game, could also make the Team 2 simultaneously, without needing several querys or anything of the kind.
To create foreign keys is easy:
`CREATE TABLE IF NOT `sua tabela` (id int NOT NULL PRIMARY KEY AUTO_INCREMENT, id_segunda_tabela int NOT NULL, FOREIGN KEY(`id_segunda_tabela`) REFERENCES `segunda_tabela`(`id_da_segunda_tabela`) ON DELETE CASCADE)`
Understand the ON DELETE CASCADE
, this serves to delete also the child record if the main table record, in the context segunda_tabela
, be excluded
In the table games, you don’t need the team, you need the team ID. From this conception, create a relationship by entering the team id instead of the name.
– Theotonio