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 "car_makers" VALUES ("1", "amc", "1");
INSERT INTO "car_makers" VALUES ("2", "Toyota", "2");
INSERT INTO "car_makers" VALUES ("3", "BMW", "3");
INSERT INTO "car_makers" VALUES ("4", "Fiat", "4");
INSERT INTO "model_list" VALUES ("1", "1", "amc hornet sportabout sw");
INSERT INTO "model_list" VALUES ("2", "1", "amc gremlin");
INSERT INTO "model_list" VALUES ("3", "2", "toyota corolla");
INSERT INTO "model_list" VALUES ("4", "3", "bmw 320i");
INSERT INTO "model_list" VALUES ("5", "4", "fiat 500");
INSERT INTO "car_names" VALUES ("1", "amc hornet sportabout sw", "amc");
INSERT INTO "car_names" VALUES ("2", "amc gremlin", "amc");
INSERT INTO "car_names" VALUES ("3", "toyota corolla", "Toyota");
INSERT INTO "car_names" VALUES ("4", "bmw 320i", "BMW");
INSERT INTO "car_names" VALUES ("5", "fiat 500", "Fiat");
INSERT INTO "cars_data" VALUES ("1", "150", "14.5");
INSERT INTO "cars_data" VALUES ("2", "100", "15.2");
INSERT INTO "cars_data" VALUES ("3", "110", "13.8");
INSERT INTO "cars_data" VALUES ("4", "180", "12.1");
INSERT INTO "cars_data" VALUES ("5", "70", "16.5");