PRAGMA foreign_keys = ON;

PRAGMA writable_schema = 1;
DELETE FROM sqlite_master WHERE type IN ("table", "index", "trigger");
PRAGMA writable_schema = 0;
VACUUM;

CREATE TABLE "matches" (
"loser_id" INT,
"match_num" INT,
"tourney_id" TEXT,
"tourney_name" TEXT,
"winner_id" INT,
FOREIGN KEY ("loser_id") REFERENCES "players"("player_id"),
FOREIGN KEY ("winner_id") REFERENCES "players"("player_id")
);

CREATE TABLE "players" (
"player_id" INT UNIQUE,
"last_name" TEXT,
PRIMARY KEY ("player_id")
);

CREATE TABLE "rankings" (
"ranking_date" DATE
);





INSERT INTO "players" VALUES ("1", "Williams");
INSERT INTO "players" VALUES ("2", "Sharapova");
INSERT INTO "players" VALUES ("3", "Serena");
INSERT INTO "players" VALUES ("4", "Venus");
INSERT INTO "players" VALUES ("5", "Azarenka");
INSERT INTO "players" VALUES ("6", "Kvitova");
INSERT INTO "players" VALUES ("7", "Halep");
INSERT INTO "players" VALUES ("8", "Kerber");
INSERT INTO "players" VALUES ("9", "Svitolina");
INSERT INTO "players" VALUES ("10", "Pliskova");
INSERT INTO "matches" VALUES ("2", "1", "T001", "Australian Open", "1");
INSERT INTO "matches" VALUES ("3", "2", "T001", "Australian Open", "4");
INSERT INTO "matches" VALUES ("5", "3", "T001", "Australian Open", "6");
INSERT INTO "matches" VALUES ("7", "4", "T001", "Australian Open", "8");
INSERT INTO "matches" VALUES ("9", "5", "T001", "Australian Open", "10");
INSERT INTO "matches" VALUES ("1", "6", "T002", "French Open", "3");
INSERT INTO "matches" VALUES ("4", "7", "T002", "French Open", "5");
INSERT INTO "matches" VALUES ("6", "8", "T002", "French Open", "7");
INSERT INTO "matches" VALUES ("10", "9", "T002", "French Open", "2");
INSERT INTO "matches" VALUES ("8", "10", "T002", "French Open", "9");
INSERT INTO "matches" VALUES ("1", "11", "T003", "Wimbledon", "5");
INSERT INTO "matches" VALUES ("2", "12", "T003", "Wimbledon", "7");
INSERT INTO "matches" VALUES ("3", "13", "T003", "Wimbledon", "9");
INSERT INTO "matches" VALUES ("4", "14", "T003", "Wimbledon", "10");
INSERT INTO "matches" VALUES ("5", "15", "T003", "Wimbledon", "1");
INSERT INTO "rankings" VALUES ("2024-01-01");
INSERT INTO "rankings" VALUES ("2024-02-01");
INSERT INTO "rankings" VALUES ("2024-03-01");
INSERT INTO "rankings" VALUES ("2024-04-01");
INSERT INTO "rankings" VALUES ("2024-05-01");