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 "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

CREATE TABLE "drivers" (
"driverId" INT UNIQUE,
"forename" TEXT,
"surname" TEXT,
PRIMARY KEY ("driverId")
);

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"grid" INT,
"position" INT,
"positionText" TEXT,
"points" FLOAT,
PRIMARY KEY ("resultId"),
FOREIGN KEY ("raceId") REFERENCES "races"("raceId"),
FOREIGN KEY ("driverId") REFERENCES "drivers"("driverId")
);



INSERT INTO "constructors" VALUES ("1", "Mercedes");
INSERT INTO "constructors" VALUES ("2", "Ferrari");
INSERT INTO "constructors" VALUES ("3", "Red Bull Racing");
INSERT INTO "drivers" VALUES ("44", "Lewis", "Hamilton");
INSERT INTO "drivers" VALUES ("5", "Sebastian", "Vettel");
INSERT INTO "drivers" VALUES ("33", "Max", "Verstappen");
INSERT INTO "drivers" VALUES ("7", "Kimi", "Raikkonen");
INSERT INTO "drivers" VALUES ("3", "Daniel", "Ricciardo");
INSERT INTO "races" VALUES ("101", "2017", "Chinese Grand Prix", "2017-04-09");
INSERT INTO "races" VALUES ("102", "2017", "Bahrain Grand Prix", "2017-04-16");
INSERT INTO "results" VALUES ("1001", "101", "44", "2", "1", "1", "25.0");
INSERT INTO "results" VALUES ("1002", "101", "5", "1", "2", "2", "18.0");
INSERT INTO "results" VALUES ("1003", "101", "33", "3", "3", "3", "15.0");
INSERT INTO "results" VALUES ("1004", "101", "7", "4", "5", "5", "10.0");
INSERT INTO "results" VALUES ("1005", "101", "3", "5", "7", "7", "6.0");
INSERT INTO "results" VALUES ("1006", "102", "44", "1", "1", "1", "25.0");
INSERT INTO "results" VALUES ("1007", "102", "5", "2", "3", "3", "15.0");
INSERT INTO "results" VALUES ("1008", "102", "33", "3", "2", "2", "18.0");