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

CREATE TABLE "airports" (
"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 Air Lines", "United States");
INSERT INTO "airlines" VALUES ("2", "Lufthansa", "Germany");
INSERT INTO "airlines" VALUES ("3", "Air Canada", "Canada");
INSERT INTO "airlines" VALUES ("4", "Qantas", "Australia");
INSERT INTO "airlines" VALUES ("5", "Emirates", "United Arab Emirates");
INSERT INTO "airports" VALUES ("JFK", "John F. Kennedy International Airport");
INSERT INTO "airports" VALUES ("LHR", "London Heathrow Airport");
INSERT INTO "airports" VALUES ("FRA", "Frankfurt Airport");
INSERT INTO "airports" VALUES ("YYZ", "Toronto Pearson International Airport");
INSERT INTO "airports" VALUES ("SYD", "Sydney Kingsford Smith Airport");
INSERT INTO "airports" VALUES ("DXB", "Dubai International Airport");
INSERT INTO "airports" VALUES ("ATL", "Hartsfield-Jackson Atlanta International Airport");
INSERT INTO "airports" VALUES ("MEL", "Melbourne Airport");
INSERT INTO "flights" VALUES ("1", "1001", "JFK", "LHR");
INSERT INTO "flights" VALUES ("1", "1002", "ATL", "JFK");
INSERT INTO "flights" VALUES ("2", "2001", "FRA", "LHR");
INSERT INTO "flights" VALUES ("2", "2002", "LHR", "FRA");
INSERT INTO "flights" VALUES ("3", "3001", "YYZ", "JFK");
INSERT INTO "flights" VALUES ("3", "3002", "JFK", "YYZ");
INSERT INTO "flights" VALUES ("4", "4001", "SYD", "MEL");
INSERT INTO "flights" VALUES ("4", "4002", "MEL", "SYD");
INSERT INTO "flights" VALUES ("5", "5001", "DXB", "LHR");
INSERT INTO "flights" VALUES ("5", "5002", "LHR", "DXB");
INSERT INTO "flights" VALUES ("5", "5003", "DXB", "JFK");