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,
"GP" 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";

View File

@ -21,7 +21,9 @@ CREATE TABLE IF NOT EXISTS "pk_appearances" (
"G_dh" NUMERIC,
"G_ph" 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";

View File

@ -6,7 +6,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsmanagers" (
"lgID" TEXT,
"tie" 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";

View File

@ -6,7 +6,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsplayers" (
"lgID" TEXT,
"tie" 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";

View File

@ -7,7 +7,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardssharemanagers" (
"pointsWon" NUMERIC,
"pointsMax" 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";

View File

@ -7,7 +7,8 @@ CREATE TABLE IF NOT EXISTS "pk_awardsshareplayers" (
"pointsWon" NUMERIC,
"pointsMax" 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";

View File

@ -22,7 +22,9 @@ CREATE TABLE IF NOT EXISTS "pk_batting" (
"SH" NUMERIC,
"SF" 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";

View File

@ -22,7 +22,9 @@ CREATE TABLE IF NOT EXISTS "pk_battingpost" (
"SH" NUMERIC,
"SF" 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";

View File

@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS "pk_collegeplaying" (
"playerID" TEXT,
"schoolID" TEXT,
"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";

View File

@ -18,7 +18,9 @@ CREATE TABLE IF NOT EXISTS "pk_fielding" (
"SB" NUMERIC,
"CS" 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";

View File

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

View File

@ -18,7 +18,9 @@ CREATE TABLE IF NOT EXISTS "pk_fieldingofsplit" (
"SB" NUMERIC,
"CS" 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";

View File

@ -17,7 +17,9 @@ CREATE TABLE IF NOT EXISTS "pk_fieldingpost" (
"PB" NUMERIC,
"SB" 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";

View File

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

View File

@ -9,7 +9,9 @@ CREATE TABLE IF NOT EXISTS "pk_homegames" (
"games" NUMERIC,
"openings" 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";

View File

@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS "pk_managers" (
"L" NUMERIC,
"rank" NUMERIC,
"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";
DROP TABLE "managers";

View File

@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS "pk_managershalf" (
"W" NUMERIC,
"L" 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";

View File

@ -30,7 +30,9 @@ CREATE TABLE IF NOT EXISTS "pk_pitching" (
"SH" NUMERIC,
"SF" 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";

View File

@ -30,7 +30,9 @@ CREATE TABLE IF NOT EXISTS "pk_pitchingpost" (
"SH" NUMERIC,
"SF" 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";

View File

@ -5,7 +5,9 @@ CREATE TABLE IF NOT EXISTS "pk_salaries" (
"lgID" TEXT,
"playerID" TEXT,
"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";

View File

@ -9,7 +9,9 @@ CREATE TABLE IF NOT EXISTS "pk_seriespost" (
"wins" NUMERIC,
"losses" 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";

View File

@ -48,7 +48,8 @@ CREATE TABLE IF NOT EXISTS "pk_teams" (
"teamIDBR" TEXT,
"teamIDlahman45" 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";

View File

@ -10,7 +10,8 @@ CREATE TABLE IF NOT EXISTS "pk_teamshalf" (
"G" NUMERIC,
"W" 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";