7. Databases and JDBC
Activity 1: Track Your Progress
Solution
- The
student
table 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
chapter
table has achapter number
and aname
:CREATE TABLE IF NOT EXISTS chapter ( CHAPTER_ID long, CHAPTER_NAME varchar(255), PRIMARY KEY (CHAPTER_ID) );
Note that the
chapter ID
is thechapter number
. - The
student_progress
table maps astudent ID
to 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 ID
andchapter ID
as 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...