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 "airlines" (
"uid" INT,
"Airline" TEXT,
"Abbreviation" TEXT,
PRIMARY KEY ("uid")
);

CREATE TABLE "airports" (
"City" TEXT,
"AirportCode" TEXT UNIQUE,
"Country" 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 "airlines" VALUES ("1", "United Airlines", "UA");
INSERT INTO "airlines" VALUES ("2", "Delta Airlines", "DL");
INSERT INTO "airlines" VALUES ("3", "American Airlines", "AA");
INSERT INTO "airlines" VALUES ("4", "Southwest Airlines", "WN");
INSERT INTO "airlines" VALUES ("5", "Lufthansa", "LH");
INSERT INTO "airlines" VALUES ("6", "British Airways", "BA");
INSERT INTO "airports" VALUES ("Chicago", "ORD", "USA");
INSERT INTO "airports" VALUES ("Aberdeen", "ABZ", "UK");
INSERT INTO "airports" VALUES ("New York", "JFK", "USA");
INSERT INTO "airports" VALUES ("London", "LHR", "UK");
INSERT INTO "airports" VALUES ("Frankfurt", "FRA", "Germany");
INSERT INTO "airports" VALUES ("Dallas", "DFW", "USA");
INSERT INTO "airports" VALUES ("Houston", "IAH", "USA");
INSERT INTO "airports" VALUES ("Aberdeen", "APG", "USA");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "USA");
INSERT INTO "flights" VALUES ("1", "101", "ORD", "ABZ");
INSERT INTO "flights" VALUES ("1", "102", "JFK", "ABZ");
INSERT INTO "flights" VALUES ("1", "103", "LHR", "JFK");
INSERT INTO "flights" VALUES ("2", "201", "JFK", "LHR");
INSERT INTO "flights" VALUES ("3", "301", "DFW", "ORD");
INSERT INTO "flights" VALUES ("1", "104", "ORD", "JFK");
INSERT INTO "flights" VALUES ("1", "105", "IAH", "ABZ");
INSERT INTO "flights" VALUES ("1", "106", "ORD", "APG");
INSERT INTO "flights" VALUES ("1", "107", "JFK", "ABR");
INSERT INTO "flights" VALUES ("4", "401", "ORD", "ABZ");
INSERT INTO "flights" VALUES ("5", "501", "FRA", "ABZ");
INSERT INTO "flights" VALUES ("6", "601", "LHR", "ABZ");