1022 B
1022 B
SEN-209: Lab 3 - ERD & SQL CRUD
Insert 3 students and 2 courses
INSERT INTO students VALUES (1000, 'Peter', 'Parker', '2001-08-10'), (1001, 'Miles', 'Morales', '2001-08-03'), (1002, 'Gwen', 'Stacy', '2001-04-18');
INSERT INTO courses VALUES ('2sf3Lf', 'Physics I', 5), ('XjxDA6', 'Chemistry I', 6),
Enroll students into courses with grades
INSERT INTO enrollment VALUES (1000, 'XjxDA6', 'A'), (1000, '2sf3Lf', 'A+'), (1001, '2sf3Lf', 'B'), (1002, 'XjxDA6', 'A'), (1002, '2sf3Lf', 'A+');
Retrieve all students with their enrolled courses
SELECT st.fname, st.lname, STRING_AGG ( c.cName, ',' ) enrolled FROM students st INNER JOIN enrollment e ON e.sID = st.sID INNER JOIN courses c ON c.cID = e.cID GROUP BY st.fname, st.lname;
Update one student's grade
UPDATE enrollment SET grade = 'A' WHERE sID = 1001 AND cID = '2sf3Lf';
Delete one enrollment record
DELETE FROM enrollment WHERE sID = 1002 AND cID = 'XjxDA6';