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,
"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", "Air Scotland");
INSERT INTO "airlines" VALUES ("2", "Global Air");
INSERT INTO "airlines" VALUES ("3", "Continental Wings");
INSERT INTO "airlines" VALUES ("4", "Sky High");
INSERT INTO "airlines" VALUES ("5", "Northern Flights");
INSERT INTO "airports" VALUES ("Aberdeen", "ABZ", "United Kingdom");
INSERT INTO "airports" VALUES ("London", "LHR", "United Kingdom");
INSERT INTO "airports" VALUES ("Edinburgh", "EDI", "United Kingdom");
INSERT INTO "airports" VALUES ("New York", "JFK", "United States");
INSERT INTO "airports" VALUES ("Paris", "CDG", "France");
INSERT INTO "airports" VALUES ("Berlin", "TXL", "Germany");
INSERT INTO "airports" VALUES ("Tokyo", "HND", "Japan");
INSERT INTO "airports" VALUES ("Dubai", "DXB", "United Arab Emirates");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "United States");
INSERT INTO "airports" VALUES ("Glasgow", "GLA", "United Kingdom");
INSERT INTO "flights" VALUES ("1", "101", "ABZ", "LHR");
INSERT INTO "flights" VALUES ("1", "102", "ABZ", "EDI");
INSERT INTO "flights" VALUES ("2", "201", "ABZ", "JFK");
INSERT INTO "flights" VALUES ("2", "202", "LHR", "ABZ");
INSERT INTO "flights" VALUES ("3", "301", "EDI", "CDG");
INSERT INTO "flights" VALUES ("3", "302", "ABZ", "CDG");
INSERT INTO "flights" VALUES ("4", "401", "TXL", "ABZ");
INSERT INTO "flights" VALUES ("4", "402", "ABZ", "DXB");
INSERT INTO "flights" VALUES ("5", "501", "ABZ", "HND");
INSERT INTO "flights" VALUES ("5", "502", "GLA", "ABZ");
INSERT INTO "flights" VALUES ("1", "103", "ABZ", "GLA");
INSERT INTO "flights" VALUES ("2", "203", "ABR", "LHR");
INSERT INTO "flights" VALUES ("3", "303", "ABZ", "ABR");