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,
"round" TEXT,
"tourney_id" 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,
"first_name" TEXT,
"last_name" TEXT,
"hand" TEXT,
"birth_date" DATE,
"country_code" TEXT,
PRIMARY KEY ("player_id")
);

CREATE TABLE "rankings" (
"ranking" INT,
"player_id" INT,
FOREIGN KEY ("player_id") REFERENCES "players"("player_id")
);





INSERT INTO "players" VALUES ("1", "Serena", "Williams", "R", "1981-09-26", "USA");
INSERT INTO "players" VALUES ("2", "Venus", "Williams", "R", "1980-06-17", "USA");
INSERT INTO "players" VALUES ("3", "Simona", "Halep", "R", "1991-09-27", "ROU");
INSERT INTO "players" VALUES ("4", "Naomi", "Osaka", "R", "1997-10-16", "JPN");
INSERT INTO "players" VALUES ("5", "Ashleigh", "Barty", "L", "1996-04-24", "AUS");
INSERT INTO "players" VALUES ("6", "Petra", "Kvitova", "L", "1990-03-08", "CZE");
INSERT INTO "players" VALUES ("7", "Bianca", "Andreescu", "R", "2000-06-16", "CAN");
INSERT INTO "players" VALUES ("8", "Angelique", "Kerber", "L", "1988-01-18", "GER");
INSERT INTO "players" VALUES ("9", "Garbiñe", "Muguruza", "R", "1993-10-08", "ESP");
INSERT INTO "players" VALUES ("10", "Sloane", "Stephens", "R", "1993-03-20", "USA");
INSERT INTO "rankings" VALUES ("1", "1");
INSERT INTO "rankings" VALUES ("2", "5");
INSERT INTO "rankings" VALUES ("3", "3");
INSERT INTO "rankings" VALUES ("4", "4");
INSERT INTO "rankings" VALUES ("5", "6");
INSERT INTO "rankings" VALUES ("6", "2");
INSERT INTO "rankings" VALUES ("7", "7");
INSERT INTO "rankings" VALUES ("8", "8");
INSERT INTO "rankings" VALUES ("9", "9");
INSERT INTO "rankings" VALUES ("10", "10");
INSERT INTO "matches" VALUES ("2", "Quarterfinal", "USO2023", "1");
INSERT INTO "matches" VALUES ("3", "Semifinal", "USO2023", "1");
INSERT INTO "matches" VALUES ("5", "Final", "USO2023", "1");
INSERT INTO "matches" VALUES ("7", "Round of 16", "RG2023", "3");
INSERT INTO "matches" VALUES ("8", "Quarterfinal", "RG2023", "3");
INSERT INTO "matches" VALUES ("9", "Semifinal", "RG2023", "3");
INSERT INTO "matches" VALUES ("10", "Final", "RG2023", "3");
INSERT INTO "matches" VALUES ("4", "Round of 32", "AO2023", "5");
INSERT INTO "matches" VALUES ("6", "Round of 16", "AO2023", "5");
INSERT INTO "matches" VALUES ("1", "Quarterfinal", "AO2023", "5");