Entity Relationship Model

Student

student idnamejoin date
101Rachel Green2000-05-01
201Joey Tribianni1998-07-05
301Monica Geller1999-12-14
401Cosmo Kramer2001-06-05

Courses

student idsemestercourse
101Semester 1DBMS
101Semester 1Calculus
201Semester 1Algebra
201Semester 1Web

One to One Mapping

erDiagram
    Student {
        int student_id PK
        string name
        date join_date
    }
    
    Studentdetails {
        int student_id PK
        string SSN
        date DOB
    }
    
    Student ||--|| Studentdetails : "1 to 1"

Student

student idnamejoin date
101Rachel Green2000-05-01
201Joey Tribianni1998-07-05
301Monica Geller1999-12-14
401Cosmo Kramer2001-06-05

Studentdetails

student idSSNDOB
101123-56-78901980-05-01
201236-56-45861979-07-05
301365-45-98751980-12-14
401148-89-47581978-06-05

For every row on the left-hand side, there will be only one matching entry on the right-hand side.

For student id 101, you will find one SSN and one DOB.

One to Many Mapping

erDiagram
    Student {
        int student_id PK
        string name
        date join_date
    }
    
    Address {
        int address_id PK
        int student_id FK
        string address
        string address_type
    }
    
    Student ||--o{ Address : "has"

Student

student idnamejoin date
101Rachel Green2000-05-01
201Joey Tribianni1998-07-05
301Monica Geller1999-12-14
401Cosmo Kramer2001-06-05

Address

student idaddress idaddressaddress type
10111 main st, NYHome
10124 john blvd,NJDorm
30133 main st, NYHome
30145 john blvd,NJDorm
201512 center st, NYHome
401611 pint st, NYHome

What do you notice here?

Every row on the left-hand side has one or more rows on the right-hand side.

For student id 101, you will notice the home address and Dorm address.

Many to Many Mapping

erDiagram
    Student {
        int student_id PK
        string name
        date join_date
    }
    
    Course {
        string course_id PK
        string course_name
    }
    
    StudentCourses {
        int student_id FK
        string course_id FK
    }
    
    Student ||--o{ StudentCourses : enrolls
    Course ||--o{ StudentCourses : offered_in

Student

student idnamejoin date
101Rachel Green2000-05-01
201Joey Tribianni1998-07-05
301Monica Geller1999-12-14
401Cosmo Kramer2001-06-05

Student Courses

student idcourse id
101c1
101c2
301c1
301c3
201c3
401c4

Courses

course idcourse name
c1DataBase
c2Web Programming
c3Big Data
c4Data Warehouse

What do you notice here?

Students can take more than one course, and courses can have more than one student.