diff --git a/Makefile b/Makefile index ebc221f..2b9d652 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ bbdb = baseballdatabank-2023.1 db: baseball.db -baseball.db: sql/corrections/*.sql sql/keys/*.sql sql/1nf/*.sql +baseball.db: sql/corrections/*.sql sql/keys/*.sql sql/1nf/*.sql sql/2nf/*.sql rm -f baseball.db sqlite3 baseball.db ".import --csv $(bbdb)/core/AllstarFull.csv allstarfull" sqlite3 baseball.db ".import --csv $(bbdb)/core/Appearances.csv appearances" @@ -36,4 +36,5 @@ baseball.db: sql/corrections/*.sql sql/keys/*.sql sql/1nf/*.sql cat sql/corrections/*.sql | sqlite3 baseball.db cat sql/keys/*.sql | sqlite3 baseball.db cat sql/1nf/*.sql | sqlite3 baseball.db + cat sql/2nf/*.sql | sqlite3 baseball.db sqlite3 baseball.db "VACUUM" diff --git a/sql/2nf/appearances.sql b/sql/2nf/appearances.sql new file mode 100644 index 0000000..a1a6975 --- /dev/null +++ b/sql/2nf/appearances.sql @@ -0,0 +1,3 @@ +begin; +alter table "appearances" drop column "lgID"; +commit; diff --git a/sql/2nf/appearancespost.sql b/sql/2nf/appearancespost.sql new file mode 100644 index 0000000..116cd60 --- /dev/null +++ b/sql/2nf/appearancespost.sql @@ -0,0 +1,21 @@ +begin; +create table if not exists appearancespost ( + "yearID" numeric, + "playerID" text, + "teamID" text, + primary key("yearID","playerID") +); + +insert into appearancespost +select distinct yearID, playerID, teamID +from battingpost +union +select distinct yearID, playerID, teamID +from pitchingpost; + +alter table "battingpost" drop column "teamID"; +alter table "battingpost" drop column "lgID"; + +alter table "pitchingpost" drop column "teamID"; +alter table "pitchingpost" drop column "lgID"; +commit; diff --git a/sql/2nf/homegames.sql b/sql/2nf/homegames.sql new file mode 100644 index 0000000..500d3ed --- /dev/null +++ b/sql/2nf/homegames.sql @@ -0,0 +1,3 @@ +begin; +alter table "homegames" drop column "league.key"; +commit; diff --git a/sql/2nf/salaries.sql b/sql/2nf/salaries.sql new file mode 100644 index 0000000..23ede7a --- /dev/null +++ b/sql/2nf/salaries.sql @@ -0,0 +1,3 @@ +begin; +alter table "salaries" drop column "lgID"; +commit; diff --git a/sql/2nf/seriespost.sql b/sql/2nf/seriespost.sql new file mode 100644 index 0000000..7aae213 --- /dev/null +++ b/sql/2nf/seriespost.sql @@ -0,0 +1,4 @@ +begin; +alter table "seriespost" drop column "lgIDwinner"; +alter table "seriespost" drop column "lgIDloser"; +commit; diff --git a/sql/2nf/teamshalfdivision.sql b/sql/2nf/teamshalfdivision.sql new file mode 100644 index 0000000..ae3bf70 --- /dev/null +++ b/sql/2nf/teamshalfdivision.sql @@ -0,0 +1,15 @@ +begin; +create table if not exists "teamshalfdivisions" ( + "yearID" numeric, + "teamID" text, + "divID" text, + primary key("yearID","teamID") +); + +insert into teamshalfdivisions +select distinct yearid, teamid, divid +from teamshalf; + +alter table teamshalf drop column "lgID"; +alter table teamshalf drop column "divID"; +commit;