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 "Addresses" (
"address_id" INT UNIQUE,
"state_province_county" VARCHAR(255),
PRIMARY KEY ("address_id")
);

CREATE TABLE "Degree_Programs" (
"degree_program_id" INT,
"department_id" INT,
PRIMARY KEY ("degree_program_id")
);

CREATE TABLE "Student_Enrolment" (
"student_enrolment_id" INT,
"degree_program_id" INT,
"semester_id" INT,
"student_id" INT,
PRIMARY KEY ("student_enrolment_id"),
FOREIGN KEY ("student_id") REFERENCES "Students"("student_id"),
FOREIGN KEY ("degree_program_id") REFERENCES "Degree_Programs"("degree_program_id")
);

CREATE TABLE "Students" (
"student_id" INT UNIQUE,
"current_address_id" INT,
"permanent_address_id" INT,
"last_name" VARCHAR(40),
PRIMARY KEY ("student_id"),
FOREIGN KEY ("permanent_address_id") REFERENCES "Addresses"("address_id"),
FOREIGN KEY ("current_address_id") REFERENCES "Addresses"("address_id")
);





INSERT INTO "Addresses" VALUES ("1", "North Carolina");
INSERT INTO "Addresses" VALUES ("2", "California");
INSERT INTO "Addresses" VALUES ("3", "Texas");
INSERT INTO "Addresses" VALUES ("4", "North Carolina");
INSERT INTO "Addresses" VALUES ("5", "Florida");
INSERT INTO "Degree_Programs" VALUES ("1", "101");
INSERT INTO "Degree_Programs" VALUES ("2", "102");
INSERT INTO "Degree_Programs" VALUES ("3", "103");
INSERT INTO "Students" VALUES ("1", "1", "2", "Smith");
INSERT INTO "Students" VALUES ("2", "2", "3", "Johnson");
INSERT INTO "Students" VALUES ("3", "4", "5", "Williams");
INSERT INTO "Students" VALUES ("4", "3", "1", "Brown");
INSERT INTO "Students" VALUES ("5", "1", "4", "Jones");
INSERT INTO "Students" VALUES ("6", "5", "2", "Garcia");
INSERT INTO "Student_Enrolment" VALUES ("1", "1", "202201", "2");
INSERT INTO "Student_Enrolment" VALUES ("2", "2", "202201", "4");
INSERT INTO "Student_Enrolment" VALUES ("3", "3", "202202", "6");
INSERT INTO "Student_Enrolment" VALUES ("4", "1", "202202", "2");
INSERT INTO "Student_Enrolment" VALUES ("5", "2", "202203", "4");