add more check constraints
This commit is contained in:
parent
16ff759879
commit
0f99098de5
|
@ -53,7 +53,7 @@ create table if not exists "allstars" (
|
|||
"year" text,
|
||||
"gameNum" text,
|
||||
"team" text,
|
||||
"GP" numeric,
|
||||
"GP" numeric check ("GP" in (0, 1)),
|
||||
primary key("player","year","gameNum"),
|
||||
foreign key("year","gameNum") references "allstargames"("year","gameNum"),
|
||||
foreign key("player","year","team") references "appearances"("player","year","team")
|
||||
|
|
|
@ -43,7 +43,7 @@ CREATE TABLE "allstarstartingpos" (
|
|||
"year" NUMERIC,
|
||||
"gameNum" NUMERIC,
|
||||
"league" NUMERIC,
|
||||
"startingPos" NUMERIC,
|
||||
"startingPos" NUMERIC check ("startingPos" in (1,2,3,4,5,6,7,8,9,10)),
|
||||
primary key("year","gameNum","league","startingPos"),
|
||||
unique("year","gameNum","league","startingPos"),
|
||||
foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"),
|
||||
|
|
|
@ -6,10 +6,14 @@ attach database 'baseball-raw.db' as 'raw';
|
|||
create temp table franchises as
|
||||
select * from "raw".teamsfranchises;
|
||||
|
||||
update franchises
|
||||
set active = 'N'
|
||||
where active = 'NA';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS main."franchises" (
|
||||
"ID" TEXT,
|
||||
"name" TEXT,
|
||||
"active" TEXT,
|
||||
"active" TEXT check ("active" in ('Y','N')),
|
||||
"NAassoc" TEXT,
|
||||
PRIMARY KEY("ID")
|
||||
);
|
||||
|
|
|
@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS main."halloffame" (
|
|||
"year" NUMERIC,
|
||||
"votedBy" TEXT,
|
||||
"votes" NUMERIC,
|
||||
"inducted" TEXT,
|
||||
"inducted" TEXT check ("inducted" in ('Y','N')),
|
||||
"category" TEXT,
|
||||
PRIMARY KEY("player","year","votedBy")
|
||||
foreign key("player") references "people"("ID"),
|
||||
|
|
|
@ -14,11 +14,19 @@ insert into halloffamereqs
|
|||
select distinct yearid, votedby, ballots, needed, "needed_note"
|
||||
from "raw".halloffame;
|
||||
|
||||
update halloffamereqs
|
||||
set ballots = null
|
||||
where ballots = "";
|
||||
|
||||
update halloffamereqs
|
||||
set needed = null
|
||||
where needed = "";
|
||||
|
||||
create table if not exists main."halloffamereqs" (
|
||||
"year" numeric,
|
||||
"votedBy" text,
|
||||
"ballots" numeric,
|
||||
"needed" numeric,
|
||||
"needed" numeric check ("needed" <= "ballots"),
|
||||
"needed_note" text,
|
||||
primary key("year","votedBy"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
|
|
|
@ -14,6 +14,22 @@ update teamseasons
|
|||
set teamid = 'PHP'
|
||||
where teamid = 'PH4' and franchid = 'PHQ';
|
||||
|
||||
update teamseasons
|
||||
set divwin = null
|
||||
where divwin = '';
|
||||
|
||||
update teamseasons
|
||||
set wcwin = null
|
||||
where wcwin = '';
|
||||
|
||||
update teamseasons
|
||||
set lgwin = null
|
||||
where lgwin = '';
|
||||
|
||||
update teamseasons
|
||||
set wswin = null
|
||||
where wswin = '';
|
||||
|
||||
alter table "teamseasons" drop column "franchID";
|
||||
|
||||
create table if not exists main."teamseasons" (
|
||||
|
|
Loading…
Reference in New Issue