add foreign keys

This commit is contained in:
Nick Griffey 2024-01-25 19:49:08 -06:00
parent de4092a4a6
commit 3bd573b00d
23 changed files with 59 additions and 21 deletions

View File

@ -8,7 +8,9 @@ CREATE TABLE "pk_allstarfull" (
"lgID" NUMERIC, "lgID" NUMERIC,
"GP" NUMERIC, "GP" NUMERIC,
"startingPos" NUMERIC, "startingPos" NUMERIC,
primary key("playerID","yearID","gameNum","startingPos") primary key("playerID","yearID","gameNum","startingPos"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_allstarfull" SELECT DISTINCT * FROM "allstarfull"; INSERT INTO "pk_allstarfull" SELECT DISTINCT * FROM "allstarfull";

View File

@ -21,7 +21,9 @@ CREATE TABLE IF NOT EXISTS "pk_appearances" (
"G_dh" NUMERIC, "G_dh" NUMERIC,
"G_ph" NUMERIC, "G_ph" NUMERIC,
"G_pr" NUMERIC, "G_pr" NUMERIC,
PRIMARY KEY("yearID","teamID","playerID") PRIMARY KEY("yearID","teamID","playerID"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_appearances" SELECT DISTINCT * FROM "appearances"; INSERT INTO "pk_appearances" SELECT DISTINCT * FROM "appearances";

View File

@ -6,7 +6,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsmanagers" (
"lgID" TEXT, "lgID" TEXT,
"tie" TEXT, "tie" TEXT,
"notes" TEXT, "notes" TEXT,
PRIMARY KEY("awardID","yearID","lgID","playerID") PRIMARY KEY("awardID","yearID","lgID","playerID"),
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_awardsmanagers" SELECT DISTINCT * FROM "awardsmanagers"; INSERT INTO "pk_awardsmanagers" SELECT DISTINCT * FROM "awardsmanagers";

View File

@ -6,7 +6,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsplayers" (
"lgID" TEXT, "lgID" TEXT,
"tie" TEXT, "tie" TEXT,
"notes" TEXT, "notes" TEXT,
PRIMARY KEY("awardID","yearID","lgID","notes","playerID") PRIMARY KEY("awardID","yearID","lgID","notes","playerID"),
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_awardsplayers" SELECT DISTINCT * FROM "awardsplayers"; INSERT INTO "pk_awardsplayers" SELECT DISTINCT * FROM "awardsplayers";

View File

@ -7,7 +7,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardssharemanagers" (
"pointsWon" NUMERIC, "pointsWon" NUMERIC,
"pointsMax" NUMERIC, "pointsMax" NUMERIC,
"votesFirst" NUMERIC, "votesFirst" NUMERIC,
PRIMARY KEY("playerID","awardID","yearID","lgID") PRIMARY KEY("playerID","awardID","yearID","lgID"),
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_awardssharemanagers" SELECT DISTINCT * FROM "awardssharemanagers"; INSERT INTO "pk_awardssharemanagers" SELECT DISTINCT * FROM "awardssharemanagers";

View File

@ -7,7 +7,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsshareplayers" (
"pointsWon" NUMERIC, "pointsWon" NUMERIC,
"pointsMax" NUMERIC, "pointsMax" NUMERIC,
"votesFirst" NUMERIC, "votesFirst" NUMERIC,
PRIMARY KEY("awardID","yearID","playerID","lgID") PRIMARY KEY("awardID","yearID","playerID","lgID"),
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_awardsshareplayers" SELECT DISTINCT * FROM "awardsshareplayers"; INSERT INTO "pk_awardsshareplayers" SELECT DISTINCT * FROM "awardsshareplayers";

View File

@ -22,7 +22,9 @@ CREATE TABLE IF NOT EXISTS "pk_batting" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID") PRIMARY KEY("playerID","yearID","stint","teamID"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_batting" SELECT DISTINCT * FROM "batting"; INSERT INTO "pk_batting" SELECT DISTINCT * FROM "batting";

View File

@ -22,7 +22,9 @@ CREATE TABLE IF NOT EXISTS "pk_battingpost" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("yearID","playerID","round") PRIMARY KEY("yearID","playerID","round"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_battingpost" SELECT DISTINCT * FROM "battingpost"; INSERT INTO "pk_battingpost" SELECT DISTINCT * FROM "battingpost";

View File

@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS "pk_collegeplaying" (
"playerID" TEXT, "playerID" TEXT,
"schoolID" TEXT, "schoolID" TEXT,
"yearID" NUMERIC, "yearID" NUMERIC,
PRIMARY KEY("playerID","yearID","schoolID") PRIMARY KEY("playerID","yearID","schoolID"),
foreign key("playerID") references "people"("playerID"),
foreign key("schoolID") references "schools"("schoolID")
); );
INSERT INTO "pk_collegeplaying" SELECT DISTINCT * FROM "collegeplaying"; INSERT INTO "pk_collegeplaying" SELECT DISTINCT * FROM "collegeplaying";

View File

@ -18,7 +18,9 @@ CREATE TABLE IF NOT EXISTS "pk_fielding" (
"SB" NUMERIC, "SB" NUMERIC,
"CS" NUMERIC, "CS" NUMERIC,
"ZR" NUMERIC, "ZR" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID","POS") PRIMARY KEY("playerID","yearID","stint","teamID","POS"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_fielding" SELECT DISTINCT * FROM "fielding"; INSERT INTO "pk_fielding" SELECT DISTINCT * FROM "fielding";

View File

@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS "pk_fieldingof" (
"Gcf" NUMERIC, "Gcf" NUMERIC,
"Grf" NUMERIC, "Grf" NUMERIC,
PRIMARY KEY("playerID","yearID","stint") PRIMARY KEY("playerID","yearID","stint")
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_fieldingof" SELECT DISTINCT * FROM "fieldingof"; INSERT INTO "pk_fieldingof" SELECT DISTINCT * FROM "fieldingof";

View File

@ -18,7 +18,9 @@ CREATE TABLE IF NOT EXISTS "pk_fieldingofsplit" (
"SB" NUMERIC, "SB" NUMERIC,
"CS" NUMERIC, "CS" NUMERIC,
"ZR" NUMERIC, "ZR" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID","POS") PRIMARY KEY("playerID","yearID","stint","teamID","POS"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_fieldingofsplit" SELECT DISTINCT * FROM "fieldingofsplit"; INSERT INTO "pk_fieldingofsplit" SELECT DISTINCT * FROM "fieldingofsplit";

View File

@ -17,7 +17,9 @@ CREATE TABLE IF NOT EXISTS "pk_fieldingpost" (
"PB" NUMERIC, "PB" NUMERIC,
"SB" NUMERIC, "SB" NUMERIC,
"CS" NUMERIC, "CS" NUMERIC,
PRIMARY KEY("playerID","yearID","round","POS") PRIMARY KEY("playerID","yearID","round","POS"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_fieldingpost" SELECT DISTINCT * FROM "fieldingpost"; INSERT INTO "pk_fieldingpost" SELECT DISTINCT * FROM "fieldingpost";

View File

@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS "pk_halloffame" (
"category" TEXT, "category" TEXT,
"needed_note" TEXT, "needed_note" TEXT,
PRIMARY KEY("playerID","yearID","votedBy") PRIMARY KEY("playerID","yearID","votedBy")
foreign key("playerID") references "people"("playerID")
); );
INSERT INTO "pk_halloffame" SELECT DISTINCT * FROM "halloffame"; INSERT INTO "pk_halloffame" SELECT DISTINCT * FROM "halloffame";

View File

@ -9,7 +9,9 @@ CREATE TABLE IF NOT EXISTS "pk_homegames" (
"games" NUMERIC, "games" NUMERIC,
"openings" NUMERIC, "openings" NUMERIC,
"attendance" NUMERIC, "attendance" NUMERIC,
PRIMARY KEY("year.key","team.key","park.key") PRIMARY KEY("year.key","team.key","park.key"),
foreign key("team.key") references "teams"("teamID"),
foreign key("park.key") references "parks"("park.key")
); );
INSERT INTO "pk_homegames" SELECT DISTINCT * FROM "homegames"; INSERT INTO "pk_homegames" SELECT DISTINCT * FROM "homegames";

View File

@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS "pk_managers" (
"L" NUMERIC, "L" NUMERIC,
"rank" NUMERIC, "rank" NUMERIC,
"plyrMgr" TEXT, "plyrMgr" TEXT,
PRIMARY KEY("playerID","yearID","teamID","inseason") PRIMARY KEY("playerID","yearID","teamID","inseason"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_managers" SELECT DISTINCT * FROM "managers"; INSERT INTO "pk_managers" SELECT DISTINCT * FROM "managers";
DROP TABLE "managers"; DROP TABLE "managers";

View File

@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS "pk_managershalf" (
"W" NUMERIC, "W" NUMERIC,
"L" NUMERIC, "L" NUMERIC,
"rank" NUMERIC, "rank" NUMERIC,
PRIMARY KEY("playerID","yearID","teamID","inseason","half") PRIMARY KEY("playerID","yearID","teamID","inseason","half"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_managershalf" SELECT DISTINCT * FROM "managershalf"; INSERT INTO "pk_managershalf" SELECT DISTINCT * FROM "managershalf";

View File

@ -30,7 +30,9 @@ CREATE TABLE IF NOT EXISTS "pk_pitching" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","stint","teamID") PRIMARY KEY("playerID","yearID","stint","teamID"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_pitching" SELECT DISTINCT * FROM "pitching"; INSERT INTO "pk_pitching" SELECT DISTINCT * FROM "pitching";

View File

@ -30,7 +30,9 @@ CREATE TABLE IF NOT EXISTS "pk_pitchingpost" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","round") PRIMARY KEY("playerID","yearID","round"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_pitchingpost" SELECT DISTINCT * FROM "pitchingpost"; INSERT INTO "pk_pitchingpost" SELECT DISTINCT * FROM "pitchingpost";

View File

@ -5,7 +5,9 @@ CREATE TABLE IF NOT EXISTS "pk_salaries" (
"lgID" TEXT, "lgID" TEXT,
"playerID" TEXT, "playerID" TEXT,
"salary" NUMERIC, "salary" NUMERIC,
PRIMARY KEY("yearID","playerID","teamID") PRIMARY KEY("yearID","playerID","teamID"),
foreign key("playerID") references "people"("playerID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_salaries" SELECT DISTINCT * FROM "salaries"; INSERT INTO "pk_salaries" SELECT DISTINCT * FROM "salaries";

View File

@ -9,7 +9,9 @@ CREATE TABLE IF NOT EXISTS "pk_seriespost" (
"wins" NUMERIC, "wins" NUMERIC,
"losses" NUMERIC, "losses" NUMERIC,
"ties" NUMERIC, "ties" NUMERIC,
PRIMARY KEY("yearID","round") PRIMARY KEY("yearID","round"),
foreign key("teamIDwinner") references "teams"("teamID"),
foreign key("teamIDloser") references "teams"("teamID")
); );
INSERT INTO "pk_seriespost" SELECT DISTINCT * FROM "seriespost"; INSERT INTO "pk_seriespost" SELECT DISTINCT * FROM "seriespost";

View File

@ -48,7 +48,8 @@ CREATE TABLE IF NOT EXISTS "pk_teams" (
"teamIDBR" TEXT, "teamIDBR" TEXT,
"teamIDlahman45" TEXT, "teamIDlahman45" TEXT,
"teamIDretro" TEXT, "teamIDretro" TEXT,
PRIMARY KEY("yearID","teamID") PRIMARY KEY("yearID","teamID"),
foreign key("franchID") references "teamsfranchises"("franchID")
); );
INSERT INTO "pk_teams" SELECT DISTINCT * FROM "teams"; INSERT INTO "pk_teams" SELECT DISTINCT * FROM "teams";

View File

@ -10,7 +10,8 @@ CREATE TABLE IF NOT EXISTS "pk_teamshalf" (
"G" NUMERIC, "G" NUMERIC,
"W" NUMERIC, "W" NUMERIC,
"L" NUMERIC, "L" NUMERIC,
PRIMARY KEY("Half","yearID","teamID") PRIMARY KEY("Half","yearID","teamID"),
foreign key("teamID") references "teams"("teamID")
); );
INSERT INTO "pk_teamshalf" SELECT DISTINCT * FROM "teamshalf"; INSERT INTO "pk_teamshalf" SELECT DISTINCT * FROM "teamshalf";