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,
"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", "APN", "Aberdeen Regional Airport");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "Aberdeen Municipal Airport");
INSERT INTO "flights" VALUES ("1", "BA123", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("1", "BA124", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("2", "VS456", "MAN", "EDI");
INSERT INTO "flights" VALUES ("3", "EZY789", "GLA", "ABZ");
INSERT INTO "flights" VALUES ("1", "BA125", "ABZ", "APN");
INSERT INTO "flights" VALUES ("2", "VS457", "APN", "ABR");
INSERT INTO "flights" VALUES ("3", "EZY790", "ABR", "LHR");