Loading Depth Study
Preparing your workspace
Relationships connect records across tables, while foreign keys reference records in another table.
Real applications contain related entities. One user can have many enrollments, one course can have many lessons, and one enrollment belongs to a specific user and course. Relational databases represent these connections using foreign keys. Common relationship patterns include one-to-one, one-to-many, and many-to-many. Understanding relationships is one of the most important database foundations.
An enrollments table can contain user_id and course_id, connecting each enrollment to one user and one course.
CREATE TABLE enrollments ( id uuid PRIMARY KEY, user_id uuid REFERENCES users(id), course_id uuid REFERENCES courses(id) );
The enrollment record references the related user and course records.