Introduction to Information System 2023/2024 Handout: Lab 3
Lab 3
Lap contents:
➢ Types of keys:
− Primary Key
− foreign Key
− Composite Key
➢ Relationships Between Tables:
− Types of relationships (One-to-One, One-to-Many, Many-to-Many)
− Creating and managing relationships
Type of Keys
1) Primary Key
▪ Definition: A primary key is a special ID assigned to each item in a
table. It's unique and ensures no duplicates
▪ Examples: fingerprint , national ID , Student ID
2) Foreign Key
▪ Definition: Foreign Key: A foreign key is a column in a table that links
to the primary key in another table. It helps establish relationships
between tables
3) Composite Key
▪ Definition: A composite key is a combination of two or more columns
that together uniquely identify each record in a database table.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Example for this Keys:
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Relationships Between Tables
• Relationships in a database are like connections between tables that help
organize and link related information.
Why Relationships are Important?
• Accuracy: Relationships keep data accurate by linking related information
together.
• Speed: Linked tables make finding information faster and easier.
• Adaptability: Relationships allow changes to be made to the database
structure without causing problems.
• Rules: Relationships enforce rules to ensure data follows the right guidelines.
Types of relationships
• One to One (1:1)
In a one-to-one relationship, each record in the first table is related to
exactly one record in the second table, and vice versa.
Example: One person has exactly one passport, and each passport
belongs to only one person.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
• One to Many (1:M)
In a one-to-many relationship, a single record in one table can be
associated with multiple records in another table, but each record in the
second table is associated with only one record in the first table.
Example: each father can have multiple sons and each son belongs to
only one father
Father Son
Father id Son id
Name Name
Phone Father_ID
• Many to Many (M:n)
Multiple records in one table can be related to multiple records in
another table, and vice versa.
Example: Each student can enroll in multiple courses and Each course
can have multiple students enrolled.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
In our Case study:
Students Table:
Instructors Table:
Courses Table:
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Grades Table:
InstructorCourse Table:
StudentCourse Table:
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Let us now create the Relationships
1) First close all tables
2) Go to the Database Tools tab to make Relationships.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
3) Add All Tables to the relationship window by clicking "Relationships
Design" then tap to " Add Tables"
4) Select all tables then click Add
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Create Relationships:
1) Grades and Students
• Each student can have multiple grades, but each grade belongs to only
one student.
• One-to-many relationship
• Linked by the Student ID in the Grades Table.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
2) Grades and Courses
• Each course can have multiple grades, but each grade belongs to only
one course.
• One-to-many relationship
• Linked by the Course ID in the Grades Table.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
3) Courses and Instructors
• Many-to-many relationship
• Each course can have multiple instructors, and each instructor can teach
multiple courses.
• Linked by the CourseInstructor Table, which establishes the association
between courses and instructors.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
4) Courses and Students
• Many-to-many relationship
• Each student can enroll in multiple courses, and each course can have
multiple students.
• Linked by the StudentCourse Table, which establishes the association
between students and courses.
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled
Relationships Final Result
Eng. Rana Khaled| Eng. Nadeen Ayman| Eng. Omnia Khaled