Menu
Theme
Bachelor of Science in Computer Science
Course Content

ER Diagrams

Database Systems

Jenga Database Kama Pro! An Introduction to ER Diagrams

Sasa! Welcome to our class on Database Systems. Think about building a house in your ushago (rural home). Would you just start mixing cement and laying bricks randomly? Of course not! You'd first get an architect to draw a detailed plan, a blueprint. This blueprint shows where the rooms will be, how they connect, where the doors and windows go. It’s the master plan.

In the world of databases, an Entity-Relationship (ER) Diagram is our blueprint. It’s a visual map that shows us how we will store our data and how all the different pieces of information relate to each other. Before you write a single line of code to create a database, you draw an ERD. Let's learn how to become database architects!

The Main Ingredients: Entities, Attributes, and Relationships

Every ER Diagram is built from three basic components. Let's break them down using an example we all know: a simple school system.

  • Entity: This is a "thing" or object of importance that we want to store information about. Think of it as a noun. In our school system, the main entities would be STUDENT, COURSE, and LECTURER. In an ERD, we draw an entity as a rectangle.
    
      +-----------+
      |  STUDENT  |
      +-----------+
            
  • Attribute: These are the properties or characteristics of an entity. If our entity is STUDENT, what information do we need about them? Their name, admission number, date of birth, etc. These are attributes. We draw them as ovals connected to the entity.
    • The most important attribute is the Primary Key. This is a unique identifier for each record in the entity. For a student, the AdmissionNumber is perfect because no two students have the same one. It's like your National ID number! We usually underline the primary key.

    Image Suggestion: A vibrant illustration of a Kenyan student's ID card. The card clearly shows fields like 'Name', 'Admission No.', 'Course', and 'Date of Birth'. The 'Admission No.' field is highlighted with a golden glow to signify it as a unique Primary Key. The style is modern and clean.

    
          ( Name )
              |
      +-----------+    ( AdmissionNumber )
      |  STUDENT  |---(______________)
      +-----------+
              |
          ( County )
            
  • Relationship: This shows how two or more entities are connected. Think of it as a verb. A STUDENT enrolls in a COURSE. A LECTURER teaches a COURSE. We draw relationships using a diamond shape.
    
      +-----------+           +----------+
      |  STUDENT  |<>--- enrolls in ---<>|  COURSE  |
      +-----------+           +----------+
            

The Rules of the Game: Cardinality

Okay, so we know entities are connected. But how are they connected? Cardinality defines the numerical relationship between entities. It answers the question, "How many?". We use a notation called "Crow's Foot Notation" because it looks like a bird's foot!

There are three main types of cardinality:

  1. One-to-One (1:1): One instance of an entity is associated with exactly one instance of another entity.
    Example: In Kenya, one PRESIDENT is the head of one COUNTRY. One DRIVER is assigned one specific UBER_CAR for a shift.
    
      ENTITY A |----| ENTITY B
      (One and only one)
            
  2. One-to-Many (1:M): One instance of an entity can be associated with many instances of another entity.
    Example: One COUNTY has many SUB-COUNTIES. One LECTURER teaches many STUDENTS. This is very common!
    
      ENTITY A |----< ENTITY B
      (The three lines, the "crow's foot", mean 'many')
            
  3. Many-to-Many (M:N): Many instances of an entity can be associated with many instances of another entity.
    Example: One STUDENT can enroll in many COURSES, and one COURSE can have many STUDENTS. Think of your own course registration!
    
      ENTITY A >----< ENTITY B
      ('Many' on both sides)
            

Twende Kazi! Let's Design a Simple University System

Let's put everything together and design a simple ERD for a university department. We need to keep track of students, the courses they take, and the lecturers who teach them.

Step 1: Identify the Entities

Easy! We've already mentioned them: STUDENT, COURSE, LECTURER.

Step 2: Identify the Attributes & Primary Keys

  • STUDENT: StudentID, StudentName, Email, PhoneNumber
  • COURSE: CourseCode, CourseName, Credits
  • LECTURER: LecturerID, LecturerName, Department

Step 3: Define the Relationships & Cardinality

  • How do a LECTURER and a COURSE relate? A lecturer teaches a course.
    • Can one lecturer teach many courses? Yes.
    • Can one course be taught by many lecturers? For this simple system, let's say no, one course has one main lecturer.
    • So, the relationship is One-to-Many (1:M). One LECTURER teaches many COURSES.
  • How do a STUDENT and a COURSE relate? A student enrolls in a course.
    • Can one student enroll in many courses? Yes, of course.
    • Can one course have many students? Absolutely!
    • So, the relationship is Many-to-Many (M:N).

Step 4: Draw the Diagram!

Now we combine all our pieces into the final blueprint. This is our ERD.


  +------------+       (teaches)        +----------+
  |  LECTURER  | |<------------------->|  COURSE  |
  +------------+       (1:M)            +----------+
       |                                     ^
       | (LecturerID)                        | (CourseCode)
       | (LecturerName)                      | (CourseName)
       |                                     |
       |                                     |
       +-------------------------------------+
                                             |
                                          (enrolls in)
                                             | (M:N)
                                             |
                                             v
                                        +-----------+
                                        |  STUDENT  |
                                        +-----------+
                                             | (StudentID)
                                             | (StudentName)

  // KEY:
  // |<  -- This is the 'Many' side (crow's foot)
  // --|  -- This is the 'One' side (single dash)
Real-World Scenario: A SACCO System

Imagine you're building a system for your local Boda Boda SACCO. Your ERD would be the first step! You'd have an entity for MEMBER (with attributes like MemberID, Name, Phone Number). Another entity would be LOAN (LoanID, Amount, Date). The relationship would be "takes". One MEMBER can take many LOANS (a 1:M relationship). This simple diagram helps you plan a powerful system to manage all their finances!

You've Got the Blueprint!

And there you have it! An ER Diagram is not as complicated as it looks. It's a powerful tool for planning and communication. By mastering how to draw these blueprints, you are taking a massive step towards designing efficient, logical, and powerful databases.

Remember the key parts: Entities (the nouns), Attributes (the properties), and Relationships (the verbs), with Cardinality setting the rules. Now you have the skills to start designing your own systems. Kazi nzuri! Keep practicing!

Pro Tip

Take your own short notes while going through the topics.

KenyaEdu
Add KenyaEdu to Home Screen
For offline access and faster experience