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,
"Country" TEXT,
PRIMARY KEY ("Id")
);

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

CREATE TABLE "cars_data" (
"Id" INT,
"Edispl" FLOAT,
"Horsepower" TEXT,
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", "Sweden");
INSERT INTO "car_makers" VALUES ("2", "Toyota", "Japan");
INSERT INTO "car_makers" VALUES ("3", "Ford", "USA");
INSERT INTO "car_makers" VALUES ("4", "BMW", "Germany");
INSERT INTO "car_makers" VALUES ("5", "Hyundai", "South Korea");
INSERT INTO "model_list" VALUES ("101", "1", "volvo");
INSERT INTO "model_list" VALUES ("102", "1", "volvo_xc90");
INSERT INTO "model_list" VALUES ("103", "2", "corolla");
INSERT INTO "model_list" VALUES ("104", "3", "mustang");
INSERT INTO "model_list" VALUES ("105", "4", "x5");
INSERT INTO "model_list" VALUES ("106", "5", "elantra");
INSERT INTO "car_names" VALUES ("101", "volvo");
INSERT INTO "car_names" VALUES ("102", "volvo_xc90");
INSERT INTO "car_names" VALUES ("103", "corolla");
INSERT INTO "car_names" VALUES ("104", "mustang");
INSERT INTO "car_names" VALUES ("105", "x5");
INSERT INTO "car_names" VALUES ("106", "elantra");
INSERT INTO "cars_data" VALUES ("101", "2.0", "250hp");
INSERT INTO "cars_data" VALUES ("102", "2.5", "300hp");
INSERT INTO "cars_data" VALUES ("103", "1.8", "140hp");
INSERT INTO "cars_data" VALUES ("104", "5.0", "450hp");
INSERT INTO "cars_data" VALUES ("105", "3.0", "335hp");
INSERT INTO "cars_data" VALUES ("106", "2.0", "147hp");
INSERT INTO "car_makers" VALUES ("6", "volvo", "Sweden");
INSERT INTO "model_list" VALUES ("107", "6", "volvo_s60");
INSERT INTO "car_names" VALUES ("107", "volvo_s60");
INSERT INTO "cars_data" VALUES ("107", "2.3", "280hp");
INSERT INTO "car_makers" VALUES ("7", "volvo", "Sweden");
INSERT INTO "model_list" VALUES ("108", "7", "volvo_v90");
INSERT INTO "car_names" VALUES ("108", "volvo_v90");
INSERT INTO "cars_data" VALUES ("108", "2.4", "310hp");
INSERT INTO "car_makers" VALUES ("8", "volvo", "Sweden");
INSERT INTO "model_list" VALUES ("109", "8", "volvo");
INSERT INTO "car_names" VALUES ("109", "volvo");
INSERT INTO "cars_data" VALUES ("109", "1.9", "220hp");