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

CREATE TABLE "airports" (
"City" TEXT,
"AirportCode" TEXT UNIQUE,
"AirportName" TEXT,
"Country" TEXT,
"CountryAbbrev" 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 States");
INSERT INTO "airlines" VALUES ("2", "Canada");
INSERT INTO "airlines" VALUES ("3", "United Kingdom");
INSERT INTO "airlines" VALUES ("4", "Germany");
INSERT INTO "airlines" VALUES ("5", "Japan");
INSERT INTO "airports" VALUES ("New York", "JFK", "John F. Kennedy International Airport", "United States", "US");
INSERT INTO "airports" VALUES ("Los Angeles", "LAX", "Los Angeles International Airport", "United States", "US");
INSERT INTO "airports" VALUES ("Toronto", "YYZ", "Toronto Pearson International Airport", "Canada", "CA");
INSERT INTO "airports" VALUES ("London", "LHR", "Heathrow Airport", "United Kingdom", "UK");
INSERT INTO "airports" VALUES ("Berlin", "TXL", "Berlin Tegel Airport", "Germany", "DE");
INSERT INTO "airports" VALUES ("Tokyo", "HND", "Haneda Airport", "Japan", "JP");
INSERT INTO "airports" VALUES ("Vancouver", "YVR", "Vancouver International Airport", "Canada", "CA");
INSERT INTO "airports" VALUES ("Frankfurt", "FRA", "Frankfurt Airport", "Germany", "DE");
INSERT INTO "airports" VALUES ("Chicago", "ORD", "O'Hare International Airport", "United States", "US");
INSERT INTO "airports" VALUES ("Osaka", "KIX", "Kansai International Airport", "Japan", "JP");
INSERT INTO "flights" VALUES ("1", "100", "JFK", "LAX");
INSERT INTO "flights" VALUES ("1", "101", "LAX", "ORD");
INSERT INTO "flights" VALUES ("2", "200", "YYZ", "YVR");
INSERT INTO "flights" VALUES ("2", "201", "YVR", "YYZ");
INSERT INTO "flights" VALUES ("3", "300", "LHR", "TXL");
INSERT INTO "flights" VALUES ("3", "301", "TXL", "LHR");
INSERT INTO "flights" VALUES ("4", "400", "FRA", "TXL");
INSERT INTO "flights" VALUES ("4", "401", "TXL", "FRA");
INSERT INTO "flights" VALUES ("5", "500", "HND", "KIX");
INSERT INTO "flights" VALUES ("5", "501", "KIX", "HND");