grade_sheet has the key (student_id, course_id). Each course's title and credits repeat once per student.
To make a table from a query, use CREATE TABLE … AS:
CREATE TABLE t2 ASnew tableSELECT DISTINCT a, b FROM tany query
It copies the columns and the rows. It does not copy keys: add the primary key after it with ALTER TABLE … ADD PRIMARY KEY (…) (Chapter 5). CREATE TABLE and then INSERT … SELECT (Chapter 6) also work.
titleandcreditsdepend on which part of the key?- Create
course_info(course_id, title, credits)with one row per course andcourse_idas its primary key. - Drop
titleandcreditsfromgrade_sheet, and make itscourse_ida foreign key tocourse_info. - Write the query that gives back the six rows of the old table:
student_id,course_id,grade,title,credits.