Tutorial 1
This tutorial is focused on the tutorial 1 exercises which can be found here.
Part 1
-
Schemas:
Students(first_name, last_name, birthday, s_id) Enrolments(s_id, course_code, year)
-
Students - 4 columns by 5 rows
Enrolments - 3 columns by 9 rows
-
Creating tables:
CREATE TABLE Students { first_name VARCHAR(20), last_name VARCHAR(20), birthday DATE, s_id INT, CONSTRAINT PK_Students PRIMARY KEY(s_id) };
CREATE TABLE Enrollments { s_id INT, course_code CHAR(7), year INT CONSTRAINT FK_Enrollents FOREIGN KEY(s_id) REFERENCES Employees(s_id) };
-
Deleting enrolment:
DELETE FROM Enrolments WHERE s_id=4 AND course_code='COMP201';
-
Deleting column:
ALTER TABLE Students DROP COLUMN birthday;
-
Changing names:
UPDATE Students SET first_name='Leah' WHERE s_id=2;
Part 2
- Works
- Fails - Longer than 20 characters.
- Fails - Identical
s_id
. - Fails - No parent in
Students
. - Works
- Fails - No primary key (
s_id
) set. - Fails - Missing
VALUES
command. - Fails - Incorrect attribute names.
- Fails - Orphans left in
Enrollments
. - Fails - No parent in
Students
. - Fails - Orphans left in
Enrollments
. - Fails - Deletes all entries leaving orphans in
Enrollments
. - Works
- Works - Deletes all entries