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 "drivers" (
"driverId" INT UNIQUE,
"surname" TEXT,
"dob" DATE,
PRIMARY KEY ("driverId")
);

CREATE TABLE "qualifying" (
"qualifyId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
PRIMARY KEY ("qualifyId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);

CREATE TABLE "races" (
"raceId" INT UNIQUE,
"year" INT,
"circuitId" INT,
"name" TEXT,
"date" DATE,
"time" TEXT,
PRIMARY KEY ("raceId")
);



INSERT INTO "drivers" VALUES ("1", "Hamilton", "1985-01-07");
INSERT INTO "drivers" VALUES ("2", "Verstappen", "1997-09-30");
INSERT INTO "drivers" VALUES ("3", "Leclerc", "1997-10-16");
INSERT INTO "drivers" VALUES ("4", "Russell", "1998-02-23");
INSERT INTO "drivers" VALUES ("5", "Sainz", "1994-03-01");
INSERT INTO "races" VALUES ("101", "2015", "11", "Australian Grand Prix", "2015-03-15", "14:00:00");
INSERT INTO "races" VALUES ("102", "2016", "12", "Bahrain Grand Prix", "2016-04-03", "15:00:00");
INSERT INTO "races" VALUES ("103", "2017", "13", "Chinese Grand Prix", "2017-04-09", "14:30:00");
INSERT INTO "races" VALUES ("104", "2018", "14", "Azerbaijan Grand Prix", "2018-04-29", "13:00:00");
INSERT INTO "races" VALUES ("105", "2019", "15", "Spanish Grand Prix", "2019-05-12", "14:00:00");
INSERT INTO "races" VALUES ("106", "2020", "16", "Belgian Grand Prix", "2020-08-30", "15:00:00");
INSERT INTO "races" VALUES ("107", "2021", "17", "Monaco Grand Prix", "2021-05-23", "14:00:00");
INSERT INTO "races" VALUES ("108", "2022", "18", "British Grand Prix", "2022-07-03", "15:00:00");
INSERT INTO "qualifying" VALUES ("201", "101", "1", "1");
INSERT INTO "qualifying" VALUES ("202", "102", "5", "3");
INSERT INTO "qualifying" VALUES ("203", "103", "2", "2");
INSERT INTO "qualifying" VALUES ("204", "104", "3", "4");
INSERT INTO "qualifying" VALUES ("205", "105", "4", "5");
INSERT INTO "qualifying" VALUES ("206", "106", "2", "1");
INSERT INTO "qualifying" VALUES ("207", "107", "3", "2");
INSERT INTO "qualifying" VALUES ("208", "108", "4", "3");