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", "Honda", "Japan");
INSERT INTO "model_list" VALUES ("101", "1", "Volvo XC90");
INSERT INTO "model_list" VALUES ("102", "1", "Volvo S60");
INSERT INTO "model_list" VALUES ("103", "1", "Volvo V60");
INSERT INTO "model_list" VALUES ("104", "2", "Corolla");
INSERT INTO "model_list" VALUES ("105", "2", "Camry");
INSERT INTO "model_list" VALUES ("106", "3", "Mustang");
INSERT INTO "model_list" VALUES ("107", "4", "X5");
INSERT INTO "model_list" VALUES ("108", "5", "Civic");
INSERT INTO "car_names" VALUES ("101", "Volvo XC90");
INSERT INTO "car_names" VALUES ("102", "Volvo S60");
INSERT INTO "car_names" VALUES ("103", "Volvo V60");
INSERT INTO "car_names" VALUES ("104", "Corolla");
INSERT INTO "car_names" VALUES ("105", "Camry");
INSERT INTO "car_names" VALUES ("106", "Mustang");
INSERT INTO "car_names" VALUES ("107", "X5");
INSERT INTO "car_names" VALUES ("108", "Civic");
INSERT INTO "cars_data" VALUES ("101", "2.0", "250");
INSERT INTO "cars_data" VALUES ("102", "2.5", "300");
INSERT INTO "cars_data" VALUES ("103", "1.5", "190");
INSERT INTO "cars_data" VALUES ("104", "1.8", "140");
INSERT INTO "cars_data" VALUES ("105", "2.5", "178");
INSERT INTO "cars_data" VALUES ("106", "5.0", "450");
INSERT INTO "cars_data" VALUES ("107", "3.0", "335");
INSERT INTO "cars_data" VALUES ("108", "2.0", "158");