Professional Documents
Culture Documents
Relationships
Relationships
Relationships
CMPSC140
Relationships
• Definition
– An association between common fields (columns) in two tables
– One-to-One (1:1)
– One-to-Many (1:N)
– Many-to-Many (M:N)
• Advantages
– You can join and view information together from several tables
• How to define relationship
– By matching common fields – usually a field with the same name in
both tables ( one for primary, the other for foreign key)
Relationships
Keys
– Primary key: A unique value for each record
– Foreign key: A copy of a primary key which can appear in other table
– Composite Primary Key: A primary key that made up of more than
one attribute
Student Course
studentID courseID
studentName courseName
1 1
Enrollment
M StudentID (CPK) M
CourseID (CPK)
Relationships
Course
Student
CourseID (PK)
StudentID (PK) 1 M
1 CourseName
StudentName
teacherID(FK)
Enrollment Teacher
StudentID (CPK) TeacherID (PK)
M 1
CourseID (CPK) M TeacherName