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 "car_makers" (
"Id" INT UNIQUE,
"Maker" TEXT,
"FullName" TEXT,
PRIMARY KEY ("Id")
);

CREATE TABLE "car_names" (
"MakeId" INT UNIQUE,
"Model" TEXT,
"Make" TEXT,
PRIMARY KEY ("MakeId"),
FOREIGN KEY ("Model") REFERENCES "model_list"("Model")
);

CREATE TABLE "cars_data" (
"Id" INT,
"Cylinders" INT,
"Horsepower" TEXT,
"Accelerate" FLOAT,
PRIMARY KEY ("Id"),
FOREIGN KEY ("Id") REFERENCES "car_names"("MakeId")
);

CREATE TABLE "model_list" (
"ModelId" INT,
"Maker" INT,
"Model" TEXT UNIQUE,
PRIMARY KEY ("ModelId"),
FOREIGN KEY ("Maker") REFERENCES "car_makers"("Id")
);





INSERT INTO "car_makers" VALUES ("1", "volvo", "Volvo Cars");
INSERT INTO "car_makers" VALUES ("2", "toyota", "Toyota Motor Corporation");
INSERT INTO "car_makers" VALUES ("3", "ford", "Ford Motor Company");
INSERT INTO "car_makers" VALUES ("4", "bmw", "Bayerische Motoren Werke AG");
INSERT INTO "car_makers" VALUES ("5", "audi", "Audi AG");
INSERT INTO "model_list" VALUES ("101", "1", "volvo");
INSERT INTO "model_list" VALUES ("102", "2", "corolla");
INSERT INTO "model_list" VALUES ("103", "3", "mustang");
INSERT INTO "model_list" VALUES ("104", "4", "x5");
INSERT INTO "model_list" VALUES ("105", "5", "a4");
INSERT INTO "car_names" VALUES ("201", "volvo", "volvo");
INSERT INTO "car_names" VALUES ("202", "corolla", "toyota");
INSERT INTO "car_names" VALUES ("203", "mustang", "ford");
INSERT INTO "car_names" VALUES ("204", "x5", "bmw");
INSERT INTO "car_names" VALUES ("205", "a4", "audi");
INSERT INTO "cars_data" VALUES ("201", "4", "180", "7.5");
INSERT INTO "cars_data" VALUES ("202", "4", "132", "8.2");
INSERT INTO "cars_data" VALUES ("203", "8", "450", "4.3");
INSERT INTO "cars_data" VALUES ("204", "6", "300", "6.1");
INSERT INTO "cars_data" VALUES ("205", "4", "220", "6.8");
INSERT INTO "car_names" VALUES ("206", "volvo", "volvo");
INSERT INTO "cars_data" VALUES ("206", "6", "250", "6.5");
INSERT INTO "car_names" VALUES ("207", "volvo", "volvo");
INSERT INTO "cars_data" VALUES ("207", "4", "200", "7.0");
INSERT INTO "model_list" VALUES ("106", "1", "volvo_suv");
INSERT INTO "car_names" VALUES ("208", "volvo_suv", "volvo");
INSERT INTO "cars_data" VALUES ("208", "6", "280", "6.0");