rename table
This commit is contained in:
parent
ec2a2057f2
commit
45b6b1a79a
4
Makefile
4
Makefile
|
@ -9,11 +9,11 @@ baseball.db: baseball-transformed.db sql/load.sql
|
|||
cat sql/load.sql | sqlite3 baseball.db
|
||||
sqlite3 baseball.db "VACUUM"
|
||||
|
||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql
|
||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql
|
||||
rm -f baseball-transformed.db
|
||||
cp baseball-raw.db baseball-transformed.db
|
||||
cat sql/franchises.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/franchiseseasons.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/teamseasons.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/awards.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/seasons.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/parks.sql | sqlite3 baseball-transformed.db
|
||||
|
|
12
sql/load.sql
12
sql/load.sql
|
@ -20,11 +20,10 @@ CREATE TABLE IF NOT EXISTS "franchises" (
|
|||
insert into franchises
|
||||
select distinct * from "transformed"."franchises";
|
||||
|
||||
create table if not exists "franchiseseasons" (
|
||||
create table if not exists "teamseasons" (
|
||||
"year" NUMERIC,
|
||||
"league" TEXT,
|
||||
"team" TEXT,
|
||||
"franchise" TEXT,
|
||||
"division" TEXT,
|
||||
"Rank" NUMERIC,
|
||||
"G" NUMERIC,
|
||||
|
@ -69,14 +68,13 @@ create table if not exists "franchiseseasons" (
|
|||
"teamIDBR" TEXT,
|
||||
"teamIDlahman45" TEXT,
|
||||
"teamIDretro" TEXT,
|
||||
PRIMARY KEY("year","franchise"),
|
||||
PRIMARY KEY("year","team"),
|
||||
foreign key("year") references "seasons"("year"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("franchise") references "franchises"("ID")
|
||||
foreign key("team") references "teams"("ID")
|
||||
);
|
||||
|
||||
insert into franchiseseasons
|
||||
select distinct * from "transformed"."franchiseseasons";
|
||||
insert into teamseasons
|
||||
select distinct * from "transformed"."teamseasons";
|
||||
|
||||
create table if not exists "seasons" (
|
||||
"year" numeric,
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
begin;
|
||||
alter table "teams" rename to "franchiseseasons";
|
||||
alter table "teams" rename to "teamseasons";
|
||||
|
||||
update franchiseseasons
|
||||
update teamseasons
|
||||
set teamid = 'WS9'
|
||||
where teamid = 'WAS' and franchid = 'WAS';
|
||||
|
||||
update franchiseseasons
|
||||
update teamseasons
|
||||
set teamid = 'PHP'
|
||||
where teamid = 'PH4' and franchid = 'PHQ';
|
||||
|
||||
alter table "teamseasons" drop column "franchID";
|
||||
commit;
|
Loading…
Reference in New Issue