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,
"loser_name" TEXT,
"minutes" INT,
"round" TEXT,
"winner_id" INT,
"winner_name" TEXT,
FOREIGN KEY ("loser_id") REFERENCES "players"("player_id"),
FOREIGN KEY ("winner_id") REFERENCES "players"("player_id")
);

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

CREATE TABLE "rankings" (
"ranking" INT
);





INSERT INTO "players" VALUES ("1", "Serena", "Williams", "1981-09-26");
INSERT INTO "players" VALUES ("2", "Venus", "Williams", "1980-06-17");
INSERT INTO "players" VALUES ("3", "Simona", "Halep", "1991-09-27");
INSERT INTO "players" VALUES ("4", "Naomi", "Osaka", "1997-10-16");
INSERT INTO "players" VALUES ("5", "Ashleigh", "Barty", "1996-04-24");
INSERT INTO "players" VALUES ("6", "Petra", "Kvitova", "1990-03-08");
INSERT INTO "players" VALUES ("7", "Bianca", "Andreescu", "2000-06-16");
INSERT INTO "players" VALUES ("8", "Sofia", "Kenin", "1998-11-14");
INSERT INTO "rankings" VALUES ("1");
INSERT INTO "rankings" VALUES ("2");
INSERT INTO "rankings" VALUES ("3");
INSERT INTO "rankings" VALUES ("4");
INSERT INTO "rankings" VALUES ("5");
INSERT INTO "rankings" VALUES ("6");
INSERT INTO "rankings" VALUES ("7");
INSERT INTO "rankings" VALUES ("8");
INSERT INTO "matches" VALUES ("2", "Venus Williams", "210", "Final", "1", "Serena Williams");
INSERT INTO "matches" VALUES ("3", "Simona Halep", "180", "Semi-Final", "5", "Ashleigh Barty");
INSERT INTO "matches" VALUES ("6", "Petra Kvitova", "195", "Quarter-Final", "4", "Naomi Osaka");
INSERT INTO "matches" VALUES ("7", "Bianca Andreescu", "240", "Final", "8", "Sofia Kenin");
INSERT INTO "matches" VALUES ("5", "Ashleigh Barty", "150", "Round 3", "3", "Simona Halep");
INSERT INTO "matches" VALUES ("4", "Naomi Osaka", "200", "Semi-Final", "1", "Serena Williams");
INSERT INTO "matches" VALUES ("8", "Sofia Kenin", "230", "Quarter-Final", "2", "Venus Williams");
INSERT INTO "matches" VALUES ("1", "Serena Williams", "240", "Final", "7", "Bianca Andreescu");