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 ("Dublin", "DUB", "Dublin Airport");
INSERT INTO "airports" VALUES ("Belfast", "BFS", "Belfast International Airport");
INSERT INTO "airports" VALUES ("Inverness", "INV", "Inverness Airport");
INSERT INTO "airports" VALUES ("Kirkwall", "KOI", "Kirkwall Airport");
INSERT INTO "airports" VALUES ("Sumburgh", "LSI", "Sumburgh Airport");
INSERT INTO "flights" VALUES ("1", "101", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("1", "102", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("2", "203", "ABZ", "EDI");
INSERT INTO "flights" VALUES ("2", "204", "EDI", "ABZ");
INSERT INTO "flights" VALUES ("3", "305", "GLA", "LHR");
INSERT INTO "flights" VALUES ("1", "103", "ABZ", "MAN");
INSERT INTO "flights" VALUES ("4", "401", "MAN", "DUB");
INSERT INTO "flights" VALUES ("5", "502", "DUB", "BFS");
INSERT INTO "flights" VALUES ("2", "205", "ABZ", "INV");
INSERT INTO "flights" VALUES ("1", "104", "INV", "ABZ");
INSERT INTO "flights" VALUES ("3", "306", "ABZ", "KOI");
INSERT INTO "flights" VALUES ("3", "307", "KOI", "ABZ");
INSERT INTO "flights" VALUES ("2", "206", "ABZ", "LSI");
INSERT INTO "flights" VALUES ("2", "207", "LSI", "ABZ");
INSERT INTO "flights" VALUES ("1", "105", "LHR", "EDI");
INSERT INTO "flights" VALUES ("4", "402", "EDI", "GLA");