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 ("Manchester", "MAN", "Manchester Airport");
INSERT INTO "airports" VALUES ("Glasgow", "GLA", "Glasgow Airport");
INSERT INTO "airports" VALUES ("Belfast", "BFS", "Belfast International Airport");
INSERT INTO "airports" VALUES ("Dublin", "DUB", "Dublin Airport");
INSERT INTO "airports" VALUES ("Paris", "CDG", "Charles de Gaulle Airport");
INSERT INTO "airports" VALUES ("Amsterdam", "AMS", "Amsterdam Airport Schiphol");
INSERT INTO "airports" VALUES ("Frankfurt", "FRA", "Frankfurt Airport");
INSERT INTO "flights" VALUES ("101", "123", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("101", "124", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("102", "456", "ABZ", "EDI");
INSERT INTO "flights" VALUES ("103", "789", "MAN", "ABZ");
INSERT INTO "flights" VALUES ("104", "111", "ABZ", "CDG");
INSERT INTO "flights" VALUES ("105", "222", "GLA", "ABZ");
INSERT INTO "flights" VALUES ("101", "333", "ABZ", "AMS");
INSERT INTO "flights" VALUES ("102", "444", "BFS", "ABZ");
INSERT INTO "flights" VALUES ("103", "555", "ABZ", "DUB");
INSERT INTO "flights" VALUES ("104", "666", "FRA", "ABZ");
INSERT INTO "flights" VALUES ("105", "777", "ABZ", "MAN");
INSERT INTO "flights" VALUES ("101", "888", "EDI", "LHR");
INSERT INTO "flights" VALUES ("102", "999", "LHR", "MAN");