update foreign keys
This commit is contained in:
parent
4355180c43
commit
eb489be084
25
sql/load.sql
25
sql/load.sql
|
@ -164,8 +164,7 @@ CREATE TABLE IF NOT EXISTS "salaries" (
|
|||
"salary" NUMERIC,
|
||||
PRIMARY KEY("year","player","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into salaries select distinct * from "transformed"."salaries";
|
||||
|
@ -194,8 +193,7 @@ CREATE TABLE IF NOT EXISTS "batting" (
|
|||
"GIDP" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into batting select distinct * from "transformed"."batting";
|
||||
|
@ -220,8 +218,7 @@ CREATE TABLE IF NOT EXISTS "fielding" (
|
|||
"ZR" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team","POS"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into fielding select distinct * from "transformed"."fielding";
|
||||
|
@ -258,8 +255,7 @@ CREATE TABLE IF NOT EXISTS "pitching" (
|
|||
"GIDP" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into pitching select distinct * from "transformed"."pitching";
|
||||
|
@ -287,8 +283,7 @@ CREATE TABLE IF NOT EXISTS "appearances" (
|
|||
"G_pr" NUMERIC,
|
||||
PRIMARY KEY("year","team","player"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into appearances select distinct * from "transformed"."appearances";
|
||||
|
@ -304,8 +299,7 @@ CREATE TABLE IF NOT EXISTS "homegames" (
|
|||
"attendance" NUMERIC,
|
||||
PRIMARY KEY("year","team","park"),
|
||||
foreign key("park") references "parks"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into homegames select distinct * from "transformed"."homegames";
|
||||
|
@ -319,7 +313,9 @@ CREATE TABLE IF NOT EXISTS "seriespost" (
|
|||
"losses" NUMERIC,
|
||||
"ties" NUMERIC,
|
||||
PRIMARY KEY("year","round"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year") references "seasons"("year"),
|
||||
foreign key("winner") references "teams"("ID"),
|
||||
foreign key("loser") references "teams"("ID")
|
||||
);
|
||||
|
||||
insert into seriespost select distinct * from "transformed"."seriespost";
|
||||
|
@ -344,8 +340,7 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
|
|||
"ZR" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team","POS"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
foreign key("year","team") references "teamseasons"("year","team")
|
||||
);
|
||||
|
||||
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
|
||||
|
|
Loading…
Reference in New Issue