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,
PRIMARY KEY ("uid")
);

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 "airlines" VALUES ("1", "United Airlines");
INSERT INTO "airlines" VALUES ("2", "Delta Airlines");
INSERT INTO "airlines" VALUES ("3", "American Airlines");
INSERT INTO "airlines" VALUES ("4", "Southwest Airlines");
INSERT INTO "airlines" VALUES ("5", "Alaska Airlines");
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", "APG", "Phillips Army Airfield");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "Aberdeen Regional Airport");
INSERT INTO "flights" VALUES ("1", "101", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("2", "202", "EDI", "ABZ");
INSERT INTO "flights" VALUES ("3", "303", "GLA", "ABZ");
INSERT INTO "flights" VALUES ("4", "404", "MAN", "ABZ");
INSERT INTO "flights" VALUES ("1", "102", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("2", "203", "ABZ", "EDI");
INSERT INTO "flights" VALUES ("3", "304", "ABZ", "GLA");
INSERT INTO "flights" VALUES ("5", "505", "LHR", "APG");
INSERT INTO "flights" VALUES ("4", "405", "MAN", "ABR");
INSERT INTO "flights" VALUES ("1", "103", "EDI", "ABR");
INSERT INTO "flights" VALUES ("2", "204", "GLA", "APG");