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"),
FOREIGN KEY ("Country") REFERENCES "countries"("CountryId")
);

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 "countries" (
"CountryId" INT,
"CountryName" TEXT,
PRIMARY KEY ("CountryId")
);

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





INSERT INTO "countries" VALUES ("1", "Sweden");
INSERT INTO "countries" VALUES ("2", "Japan");
INSERT INTO "countries" VALUES ("3", "Germany");
INSERT INTO "countries" VALUES ("4", "USA");
INSERT INTO "countries" VALUES ("5", "South Korea");
INSERT INTO "car_makers" VALUES ("10", "Volvo", "1");
INSERT INTO "car_makers" VALUES ("20", "Toyota", "2");
INSERT INTO "car_makers" VALUES ("30", "BMW", "3");
INSERT INTO "car_makers" VALUES ("40", "Ford", "4");
INSERT INTO "car_makers" VALUES ("50", "Hyundai", "5");
INSERT INTO "model_list" VALUES ("100", "10", "XC90");
INSERT INTO "model_list" VALUES ("101", "10", "S60");
INSERT INTO "model_list" VALUES ("102", "10", "V60");
INSERT INTO "model_list" VALUES ("103", "20", "Corolla");
INSERT INTO "model_list" VALUES ("104", "20", "Camry");
INSERT INTO "model_list" VALUES ("105", "30", "X5");
INSERT INTO "model_list" VALUES ("106", "30", "M3");
INSERT INTO "model_list" VALUES ("107", "40", "Mustang");
INSERT INTO "model_list" VALUES ("108", "50", "Elantra");
INSERT INTO "car_names" VALUES ("10", "XC90");
INSERT INTO "car_names" VALUES ("11", "S60");
INSERT INTO "car_names" VALUES ("12", "V60");
INSERT INTO "car_names" VALUES ("20", "Corolla");
INSERT INTO "car_names" VALUES ("21", "Camry");
INSERT INTO "car_names" VALUES ("30", "X5");
INSERT INTO "car_names" VALUES ("31", "M3");
INSERT INTO "car_names" VALUES ("40", "Mustang");
INSERT INTO "car_names" VALUES ("50", "Elantra");
INSERT INTO "cars_data" VALUES ("10", "2.0", "250hp");
INSERT INTO "cars_data" VALUES ("11", "2.5", "300hp");
INSERT INTO "cars_data" VALUES ("12", "1.5", "180hp");
INSERT INTO "cars_data" VALUES ("20", "1.8", "140hp");
INSERT INTO "cars_data" VALUES ("21", "2.5", "178hp");
INSERT INTO "cars_data" VALUES ("30", "3.0", "335hp");
INSERT INTO "cars_data" VALUES ("31", "3.2", "425hp");
INSERT INTO "cars_data" VALUES ("40", "5.0", "450hp");
INSERT INTO "cars_data" VALUES ("50", "2.0", "147hp");