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,
"Make" TEXT,
PRIMARY KEY ("MakeId"),
FOREIGN KEY ("Model") REFERENCES "model_list"("Model")
);

CREATE TABLE "cars_data" (
"Id" INT,
"Horsepower" TEXT,
"Accelerate" FLOAT,
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", "USA");
INSERT INTO "countries" VALUES ("2", "Japan");
INSERT INTO "countries" VALUES ("3", "Germany");
INSERT INTO "countries" VALUES ("4", "Italy");
INSERT INTO "countries" VALUES ("5", "France");
INSERT INTO "car_makers" VALUES ("10", "amc", "1");
INSERT INTO "car_makers" VALUES ("20", "toyota", "2");
INSERT INTO "car_makers" VALUES ("30", "bmw", "3");
INSERT INTO "car_makers" VALUES ("40", "fiat", "4");
INSERT INTO "car_makers" VALUES ("50", "renault", "5");
INSERT INTO "model_list" VALUES ("100", "10", "amc hornet sportabout sw");
INSERT INTO "model_list" VALUES ("101", "10", "amc gremlin");
INSERT INTO "model_list" VALUES ("102", "20", "toyota corolla");
INSERT INTO "model_list" VALUES ("103", "30", "bmw 320i");
INSERT INTO "model_list" VALUES ("104", "40", "fiat 500");
INSERT INTO "model_list" VALUES ("105", "50", "renault clio");
INSERT INTO "car_names" VALUES ("100", "amc hornet sportabout sw", "amc");
INSERT INTO "car_names" VALUES ("101", "amc gremlin", "amc");
INSERT INTO "car_names" VALUES ("102", "toyota corolla", "toyota");
INSERT INTO "car_names" VALUES ("103", "bmw 320i", "bmw");
INSERT INTO "car_names" VALUES ("104", "fiat 500", "fiat");
INSERT INTO "car_names" VALUES ("105", "renault clio", "renault");
INSERT INTO "cars_data" VALUES ("100", "150hp", "9.5");
INSERT INTO "cars_data" VALUES ("101", "120hp", "10.2");
INSERT INTO "cars_data" VALUES ("102", "130hp", "8.7");
INSERT INTO "cars_data" VALUES ("103", "170hp", "7.9");
INSERT INTO "cars_data" VALUES ("104", "70hp", "12.5");
INSERT INTO "cars_data" VALUES ("105", "90hp", "11.0");