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,
PRIMARY KEY ("driverId")
);

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

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

CREATE TABLE "status" (
"statusId" INT,
"status" TEXT,
PRIMARY KEY ("statusId")
);



INSERT INTO "drivers" VALUES ("1", "Hamilton");
INSERT INTO "drivers" VALUES ("2", "Massa");
INSERT INTO "drivers" VALUES ("3", "Raikkonen");
INSERT INTO "drivers" VALUES ("4", "Button");
INSERT INTO "drivers" VALUES ("5", "Kubica");
INSERT INTO "drivers" VALUES ("6", "Heidfeld");
INSERT INTO "drivers" VALUES ("7", "Alonso");
INSERT INTO "drivers" VALUES ("8", "Bourdais");
INSERT INTO "drivers" VALUES ("9", "Nakajima");
INSERT INTO "drivers" VALUES ("10", "Fisichella");
INSERT INTO "races" VALUES ("101", "2008", "1", "Australian Grand Prix");
INSERT INTO "races" VALUES ("102", "2008", "2", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("103", "2008", "3", "Bahrain Grand Prix");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Accident");
INSERT INTO "status" VALUES ("3", "Mechanical");
INSERT INTO "status" VALUES ("4", "Disqualified");
INSERT INTO "results" VALUES ("1001", "101", "1", "1", "1", "10.0", "01:24:00.000", "5040000");
INSERT INTO "results" VALUES ("1002", "101", "2", "5", "8", "1.0", "NULL", "150000");
INSERT INTO "results" VALUES ("1003", "101", "3", "2", "2", "8.0", "NULL", "30000");
INSERT INTO "results" VALUES ("1004", "101", "4", "3", "3", "6.0", "NULL", "45000");
INSERT INTO "results" VALUES ("1005", "101", "5", "4", "4", "5.0", "NULL", "60000");
INSERT INTO "results" VALUES ("1006", "101", "6", "6", "5", "4.0", "NULL", "90000");
INSERT INTO "results" VALUES ("1007", "101", "7", "7", "6", "3.0", "NULL", "120000");
INSERT INTO "results" VALUES ("1008", "101", "8", "8", "7", "2.0", "NULL", "135000");
INSERT INTO "results" VALUES ("1009", "101", "9", "9", "9", "0.0", "NULL", "NULL");
INSERT INTO "results" VALUES ("1010", "101", "10", "10", "10", "0.0", "NULL", "NULL");
INSERT INTO "results" VALUES ("1011", "102", "1", "1", "1", "10.0", "01:30:00.000", "5400000");
INSERT INTO "results" VALUES ("1012", "102", "2", "2", "2", "8.0", "NULL", "20000");
INSERT INTO "results" VALUES ("1013", "103", "3", "1", "1", "10.0", "01:28:00.000", "5280000");