add some unique constraints

This commit is contained in:
Nick Griffey 2024-02-01 19:45:40 -06:00
parent 6f6318b5e0
commit 16ff759879
4 changed files with 15 additions and 3 deletions

View File

@ -29,7 +29,7 @@ where game = '';
create table if not exists allstargames ( create table if not exists allstargames (
"year" numeric, "year" numeric,
"gameNum" numeric, "gameNum" numeric,
"game" text, "game" text unique,
primary key("year","gameNum"), primary key("year","gameNum"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );

View File

@ -45,6 +45,7 @@ CREATE TABLE "allstarstartingpos" (
"league" NUMERIC, "league" NUMERIC,
"startingPos" NUMERIC, "startingPos" NUMERIC,
primary key("year","gameNum","league","startingPos"), primary key("year","gameNum","league","startingPos"),
unique("year","gameNum","league","startingPos"),
foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"), foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"),
foreign key("league") references "leagues"("ID") foreign key("league") references "leagues"("ID")
); );

View File

@ -12,6 +12,14 @@ insert into people values
('fowlebu99', 1858, 3, 16, 'USA', 'NY', 'Fort Plain', 1913, 2, 26, 'USA', 'NY', 'Frankfort', 'Bud', 'Fowler', 'John W. Jackson', 155, 67, 'R', 'R', null, null, null, 'fowlebu99'), ('fowlebu99', 1858, 3, 16, 'USA', 'NY', 'Fort Plain', 1913, 2, 26, 'USA', 'NY', 'Frankfort', 'Bud', 'Fowler', 'John W. Jackson', 155, 67, 'R', 'R', null, null, null, 'fowlebu99'),
('thompan01', null, null, null, null, null, null, null, null, null, null, null, null, null, 'Thompson', null, null, null, null, null, '1875-04-26', '1875-05-17', null, 'thompan01'); ('thompan01', null, null, null, null, null, null, null, null, null, null, null, null, null, 'Thompson', null, null, null, null, null, '1875-04-26', '1875-05-17', null, 'thompan01');
update people
set bbrefID = null
where bbrefID = '';
update people
set retroID = null
where retroID = '';
CREATE TABLE main."people" ( CREATE TABLE main."people" (
"ID" text, "ID" text,
"birthYear" NUMERIC, "birthYear" NUMERIC,
@ -35,8 +43,8 @@ CREATE TABLE main."people" (
"throws" text, "throws" text,
"debut" text, "debut" text,
"finalGame" text, "finalGame" text,
"retroID" text, "retroID" text unique,
"bbrefID" text, "bbrefID" text unique,
primary key("ID") primary key("ID")
); );

View File

@ -65,6 +65,9 @@ create table if not exists main."teamseasons" (
"teamIDlahman45" TEXT, "teamIDlahman45" TEXT,
"teamIDretro" TEXT, "teamIDretro" TEXT,
PRIMARY KEY("year","team"), PRIMARY KEY("year","team"),
UNIQUE("year","teamIDBR"),
UNIQUE("year","teamIDlahman45"),
UNIQUE("year","teamIDretro"),
foreign key("year") references "seasons"("year"), foreign key("year") references "seasons"("year"),
foreign key("league") references "leagues"("ID"), foreign key("league") references "leagues"("ID"),
foreign key("team") references "teams"("ID") foreign key("team") references "teams"("ID")