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

CREATE TABLE "constructors" (
"constructorId" INT,
"name" TEXT,
PRIMARY KEY ("constructorId")
);

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

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

CREATE TABLE "results" (
"resultId" INT,
"raceId" INT,
"driverId" INT,
"position" INT,
"time" TEXT,
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 "circuits" VALUES ("1", "Melbourne Grand Prix Circuit");
INSERT INTO "circuits" VALUES ("2", "Sepang International Circuit");
INSERT INTO "circuits" VALUES ("3", "Shanghai International Circuit");
INSERT INTO "circuits" VALUES ("4", "Bahrain International Circuit");
INSERT INTO "circuits" VALUES ("5", "Circuit de Catalunya");
INSERT INTO "constructors" VALUES ("1", "Ferrari");
INSERT INTO "constructors" VALUES ("2", "McLaren");
INSERT INTO "constructors" VALUES ("3", "BMW Sauber");
INSERT INTO "constructors" VALUES ("4", "Renault");
INSERT INTO "constructors" VALUES ("5", "Williams");
INSERT INTO "drivers" VALUES ("1");
INSERT INTO "drivers" VALUES ("2");
INSERT INTO "drivers" VALUES ("3");
INSERT INTO "drivers" VALUES ("4");
INSERT INTO "drivers" VALUES ("5");
INSERT INTO "drivers" VALUES ("6");
INSERT INTO "drivers" VALUES ("7");
INSERT INTO "drivers" VALUES ("8");
INSERT INTO "races" VALUES ("1", "2008", "Australian Grand Prix");
INSERT INTO "races" VALUES ("2", "2008", "Malaysian Grand Prix");
INSERT INTO "races" VALUES ("3", "2008", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("4", "2009", "Australian Grand Prix");
INSERT INTO "races" VALUES ("5", "2009", "Chinese Grand Prix");
INSERT INTO "races" VALUES ("6", "2008", "Brazilian Grand Prix");
INSERT INTO "results" VALUES ("1", "1", "1", "1", "1:34:50.616");
INSERT INTO "results" VALUES ("2", "1", "2", "2", "1:34:55.800");
INSERT INTO "results" VALUES ("3", "1", "3", "3", "1:34:56.123");
INSERT INTO "results" VALUES ("4", "3", "4", "1", "1:31:57.409");
INSERT INTO "results" VALUES ("5", "3", "5", "2", "1:32:02.115");
INSERT INTO "results" VALUES ("6", "3", "6", "3", "1:32:03.500");
INSERT INTO "results" VALUES ("7", "5", "7", "1", "1:36:20.000");
INSERT INTO "results" VALUES ("8", "5", "8", "2", "1:36:25.000");
INSERT INTO "results" VALUES ("9", "6", "1", "1", "1:31:00.000");
INSERT INTO "results" VALUES ("10", "6", "2", "2", "1:31:05.000");
INSERT INTO "status" VALUES ("1", "Finished");
INSERT INTO "status" VALUES ("2", "Retired");
INSERT INTO "status" VALUES ("3", "Disqualified");
INSERT INTO "status" VALUES ("4", "Accident");