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", "Delta Airlines");
INSERT INTO "airlines" VALUES ("2", "United Airlines");
INSERT INTO "airlines" VALUES ("3", "British Airways");
INSERT INTO "airlines" VALUES ("4", "EasyJet");
INSERT INTO "airlines" VALUES ("5", "Lufthansa");
INSERT INTO "airports" VALUES ("New York", "JFK", "John F. Kennedy International Airport");
INSERT INTO "airports" VALUES ("Los Angeles", "LAX", "Los Angeles International Airport");
INSERT INTO "airports" VALUES ("Aberdeen", "ABZ", "Aberdeen International Airport");
INSERT INTO "airports" VALUES ("London", "LHR", "Heathrow Airport");
INSERT INTO "airports" VALUES ("Frankfurt", "FRA", "Frankfurt Airport");
INSERT INTO "airports" VALUES ("Paris", "CDG", "Charles de Gaulle Airport");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "Aberdeen Regional Airport");
INSERT INTO "flights" VALUES ("1", "100", "JFK", "ABZ");
INSERT INTO "flights" VALUES ("1", "101", "LAX", "LHR");
INSERT INTO "flights" VALUES ("2", "200", "FRA", "ABZ");
INSERT INTO "flights" VALUES ("2", "201", "CDG", "JFK");
INSERT INTO "flights" VALUES ("3", "300", "LHR", "ABR");
INSERT INTO "flights" VALUES ("3", "301", "ABR", "LHR");
INSERT INTO "flights" VALUES ("4", "400", "ABZ", "CDG");
INSERT INTO "flights" VALUES ("4", "401", "LHR", "FRA");
INSERT INTO "flights" VALUES ("5", "500", "JFK", "LAX");
INSERT INTO "flights" VALUES ("5", "501", "ABZ", "FRA");