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 "airports" (
"City" TEXT,
"AirportCode" TEXT UNIQUE,
"AirportName" TEXT,
PRIMARY KEY ("AirportCode")
);

CREATE TABLE "flights" (
"Airline" INT,
"FlightNo" INT,
"SourceAirport" TEXT,
"DestAirport" TEXT,
PRIMARY KEY ("Airline", "FlightNo"),
FOREIGN KEY ("SourceAirport") REFERENCES "airports"("AirportCode"),
FOREIGN KEY ("DestAirport") REFERENCES "airports"("AirportCode")
);





INSERT INTO "airports" VALUES ("Aberdeen", "ABZ", "Aberdeen International Airport");
INSERT INTO "airports" VALUES ("London", "LHR", "Heathrow Airport");
INSERT INTO "airports" VALUES ("Edinburgh", "EDI", "Edinburgh Airport");
INSERT INTO "airports" VALUES ("Glasgow", "GLA", "Glasgow Airport");
INSERT INTO "airports" VALUES ("Manchester", "MAN", "Manchester Airport");
INSERT INTO "airports" VALUES ("Aberdeen", "FJR", "Fagernes Airport");
INSERT INTO "airports" VALUES ("Inverness", "INV", "Inverness Airport");
INSERT INTO "flights" VALUES ("101", "1", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("101", "2", "ABZ", "EDI");
INSERT INTO "flights" VALUES ("102", "3", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("103", "4", "EDI", "MAN");
INSERT INTO "flights" VALUES ("104", "5", "ABZ", "GLA");
INSERT INTO "flights" VALUES ("105", "6", "MAN", "LHR");
INSERT INTO "flights" VALUES ("106", "7", "FJR", "ABZ");
INSERT INTO "flights" VALUES ("107", "8", "ABZ", "INV");
INSERT INTO "flights" VALUES ("108", "9", "INV", "ABZ");
INSERT INTO "flights" VALUES ("109", "10", "ABZ", "LHR");