7. Databases and JDBC
Activity 1: Track Your Progress
Solution
- The
studenttable holds information on thestudent:CREATE TABLE IF NOT EXISTS student ( STUDENT_ID long, FIRST_NAME varchar(255), LAST_NAME varchar(255), PRIMARY KEY (STUDENT_ID) );
- The
chaptertable has achapter numberand aname:CREATE TABLE IF NOT EXISTS chapter ( CHAPTER_ID long, CHAPTER_NAME varchar(255), PRIMARY KEY (CHAPTER_ID) );
Note that the
chapter IDis thechapter number. - The
student_progresstable maps astudent IDto achapter ID, indicating that a particular student completed a particular chapter:CREATE TABLE IF NOT EXISTS student_progress ( STUDENT_ID long, CHAPTER_ID long, COMPLETED date, PRIMARY KEY (STUDENT_ID, CHAPTER_ID) );
Note that by using both
student IDandchapter IDas the compositeprimary key, each student can complete each chapter just once. There are no do-overs. - Here is a hypothetical student:
INSERT INTO student (STUDENT_ID, FIRST_NAME, LAST_NAME) VALUES (1, &apos...