Add keys for trickier tables

This commit is contained in:
Nick Griffey 2024-01-25 19:28:46 -06:00
parent 6ac7517a56
commit 2a304b0d5c
5 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,15 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_awardsmanagers" (
"playerID" TEXT,
"awardID" TEXT,
"yearID" NUMERIC,
"lgID" TEXT,
"tie" TEXT,
"notes" TEXT,
PRIMARY KEY("awardID","yearID","lgID","playerID")
);
INSERT INTO "pk_awardsmanagers" SELECT DISTINCT * FROM "awardsmanagers";
DROP TABLE "awardsmanagers";
ALTER TABLE "pk_awardsmanagers" RENAME TO "awardsmanagers";
COMMIT;

View File

@ -0,0 +1,15 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_awardsplayers" (
"playerID" TEXT,
"awardID" TEXT,
"yearID" NUMERIC,
"lgID" TEXT,
"tie" TEXT,
"notes" TEXT,
PRIMARY KEY("awardID","yearID","lgID","notes","playerID")
);
INSERT INTO "pk_awardsplayers" SELECT DISTINCT * FROM "awardsplayers";
DROP TABLE "awardsplayers";
ALTER TABLE "pk_awardsplayers" RENAME TO "awardsplayers";
COMMIT;

18
sql/keys/homegames.sql Normal file
View File

@ -0,0 +1,18 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_homegames" (
"year.key" NUMERIC,
"league.key" TEXT,
"team.key" TEXT,
"park.key" TEXT,
"span.first" TEXT,
"span.last" TEXT,
"games" NUMERIC,
"openings" NUMERIC,
"attendance" NUMERIC,
PRIMARY KEY("year.key","team.key","park.key")
);
INSERT INTO "pk_homegames" SELECT DISTINCT * FROM "homegames";
DROP TABLE "homegames";
ALTER TABLE "pk_homegames" RENAME TO "homegames";
COMMIT;

18
sql/keys/managers.sql Normal file
View File

@ -0,0 +1,18 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_managers" (
"playerID" TEXT,
"yearID" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"inseason" NUMERIC,
"G" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"rank" NUMERIC,
"plyrMgr" TEXT,
PRIMARY KEY("playerID","yearID","teamID","inseason")
);
INSERT INTO "pk_managers" SELECT DISTINCT * FROM "managers";
DROP TABLE "managers";
ALTER TABLE "pk_managers" RENAME TO "managers";
COMMIT;

19
sql/keys/managershalf.sql Normal file
View File

@ -0,0 +1,19 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_managershalf" (
"playerID" TEXT,
"yearID" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"inseason" NUMERIC,
"half" NUMERIC,
"G" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"rank" NUMERIC,
PRIMARY KEY("playerID","yearID","teamID","inseason","half")
);
INSERT INTO "pk_managershalf" SELECT DISTINCT * FROM "managershalf";
DROP TABLE "managershalf";
ALTER TABLE "pk_managershalf" RENAME TO "managershalf";
COMMIT;