Hello on Guided project: Creating Designing a Database topic 6: Adding The Team and Game Tables when i want to make my INSERT to the team Table i got this error.
c = “”"
INSERT INTO team
SELECT
team_id,
league,
city,
nickname,
franch_id
FROM team_codes
“”"
run_command(c)
When i check on the teams_code table i verify that there is a team with same ID repeated Twice as see below, and as team_id is a primary key i think that it must not be repeated twice, and thats the error but, in the data supplied that team repeated twice is valid, I want to know how could be handled?
I saw the solution file but i did not see how was handle this situation.
as @guabeff pointed out, judging from the data the MIL team switched leagues in 1998. Advising not to include the row is a swift solution - but possibly not best practice?
I’d suggest modifying the normalized db schema by DQ slightly - by removing the league_id column from the new team table. Doing so makes creating the team table with distinct values from the team_codes a breeze and the appropriate historical league_id for the team_appearance table would be extracted from the game_log table anyway.
Instruction - 6. Adding The Team and Game Tables
Create the team table with columns, primary key, and foreign key as shown in the schema diagram.
Select the appropriate type based on the data.
Insert the data from the team_codes table.
As you can see in the instruction, we are using team_codes table to create team table. The team_codes table is created using the team_codes.csv file and it contains some duplicate team_id like this: