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,
"Abbreviation" 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", "United Airlines", "UA");
INSERT INTO "airlines" VALUES ("2", "Delta Airlines", "DL");
INSERT INTO "airlines" VALUES ("3", "American Airlines", "AA");
INSERT INTO "airlines" VALUES ("4", "Southwest Airlines", "WN");
INSERT INTO "airlines" VALUES ("5", "Alaska Airlines", "AS");
INSERT INTO "airports" VALUES ("Aberdeen", "ABZ", "Aberdeen International Airport");
INSERT INTO "airports" VALUES ("London", "LHR", "Heathrow Airport");
INSERT INTO "airports" VALUES ("New York", "JFK", "John F. Kennedy International Airport");
INSERT INTO "airports" VALUES ("Chicago", "ORD", "O'Hare International Airport");
INSERT INTO "airports" VALUES ("Los Angeles", "LAX", "Los Angeles International Airport");
INSERT INTO "airports" VALUES ("Houston", "IAH", "George Bush Intercontinental Airport");
INSERT INTO "airports" VALUES ("Dallas", "DFW", "Dallas/Fort Worth International Airport");
INSERT INTO "airports" VALUES ("Aberdeen", "APG", "Phillips Army Airfield");
INSERT INTO "airports" VALUES ("Aberdeen", "ABR", "Aberdeen Regional Airport");
INSERT INTO "flights" VALUES ("1", "101", "JFK", "ABZ");
INSERT INTO "flights" VALUES ("1", "102", "ORD", "ABZ");
INSERT INTO "flights" VALUES ("1", "103", "LAX", "LHR");
INSERT INTO "flights" VALUES ("2", "201", "JFK", "ORD");
INSERT INTO "flights" VALUES ("3", "301", "LAX", "JFK");
INSERT INTO "flights" VALUES ("1", "104", "IAH", "ABZ");
INSERT INTO "flights" VALUES ("1", "105", "DFW", "LHR");
INSERT INTO "flights" VALUES ("4", "401", "ORD", "LAX");
INSERT INTO "flights" VALUES ("1", "106", "ABR", "ABZ");
INSERT INTO "flights" VALUES ("1", "107", "APG", "ABZ");
INSERT INTO "flights" VALUES ("1", "108", "JFK", "APG");
INSERT INTO "flights" VALUES ("1", "109", "ORD", "ABR");
INSERT INTO "flights" VALUES ("5", "501", "JFK", "ABZ");