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", "Germany");
INSERT INTO "airlines" VALUES ("3", "Japan");
INSERT INTO "airlines" VALUES ("4", "Brazil");
INSERT INTO "airlines" VALUES ("5", "Australia");
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 ("Berlin", "TXL", "Berlin Tegel Airport", "Germany", "DE");
INSERT INTO "airports" VALUES ("Munich", "MUC", "Munich Airport", "Germany", "DE");
INSERT INTO "airports" VALUES ("Tokyo", "HND", "Tokyo Haneda Airport", "Japan", "JP");
INSERT INTO "airports" VALUES ("Osaka", "KIX", "Kansai International Airport", "Japan", "JP");
INSERT INTO "airports" VALUES ("Sao Paulo", "GRU", "São Paulo–Guarulhos International Airport", "Brazil", "BR");
INSERT INTO "airports" VALUES ("Rio de Janeiro", "GIG", "Rio de Janeiro–Galeão International Airport", "Brazil", "BR");
INSERT INTO "airports" VALUES ("Sydney", "SYD", "Sydney Kingsford Smith Airport", "Australia", "AU");
INSERT INTO "airports" VALUES ("Melbourne", "MEL", "Melbourne Airport", "Australia", "AU");
INSERT INTO "airports" VALUES ("Anchorage", "ANC", "Ted Stevens Anchorage International Airport", "United States", "US");
INSERT INTO "airports" VALUES ("Frankfurt", "FRA", "Frankfurt Airport", "Germany", "DE");
INSERT INTO "flights" VALUES ("1", "100", "JFK", "LAX");
INSERT INTO "flights" VALUES ("1", "101", "LAX", "JFK");
INSERT INTO "flights" VALUES ("2", "200", "TXL", "MUC");
INSERT INTO "flights" VALUES ("2", "201", "MUC", "FRA");
INSERT INTO "flights" VALUES ("3", "300", "HND", "KIX");
INSERT INTO "flights" VALUES ("3", "301", "KIX", "HND");
INSERT INTO "flights" VALUES ("4", "400", "GRU", "GIG");
INSERT INTO "flights" VALUES ("4", "401", "GIG", "GRU");
INSERT INTO "flights" VALUES ("5", "500", "SYD", "MEL");
INSERT INTO "flights" VALUES ("5", "501", "MEL", "SYD");
INSERT INTO "flights" VALUES ("1", "102", "ANC", "JFK");
INSERT INTO "flights" VALUES ("2", "202", "FRA", "TXL");