Teaches students how to visualize database structures using Entity-Relationship Diagrams (ERDs).
How does Instagram instantly know which of its 2 billion users 'liked' your specific photo out of trillions of posts? It isn't magic—it's a perfectly mapped blueprint called an Entity-Relationship Diagram.
Before building a database, we must identify its components. An Entity is a 'thing' or 'object' in the real world that is distinguishable from all other objects (the 'noun'). For example, in a school, Student and Course are entities. Attributes are the properties that describe an entity (the 'adjectives'). A Student entity might have attributes like , , and . To keep data organized, every entity needs a Primary Key—a unique attribute, like an ID number, that ensures no two records are identical. We represent entities as rectangles and attributes as ovals in our diagrams.
Let's identify the components for a simple library database: 1. Entity: Book 2. Attributes: (Primary Key), , , . 3. Visual: Draw a rectangle labeled 'Book' with four ovals connected to it containing the attribute names.
Quick Check
If you are designing a database for a car dealership, would 'Color' be an entity or an attribute?
Answer
Attribute. It is a property that describes the 'Car' entity.
Entities don't exist in isolation; they interact. A Relationship is the association between entities (the 'verb'). We represent these with diamond shapes. The most critical part of a relationship is Cardinality, which defines the numerical constraints of the link. - One-to-One (1:1): One instance of Entity A relates to exactly one of Entity B (e.g., one Citizen has one Social Security Number). - One-to-Many (1:N): One instance of Entity A relates to many of Entity B (e.g., one Customer places many Orders). - Many-to-Many (M:N): Many instances of Entity A relate to many of Entity B (e.g., many Students enroll in many Courses).
Consider a 'User' and a 'Post' on a social media platform: 1. A single User can create multiple Posts. This is a relationship. 2. However, a 'User' and a 'Bio' would be a relationship, as one user has only one bio. 3. To represent the relationship, draw a diamond labeled 'Creates' between the 'User' and 'Post' rectangles, marking '1' near User and 'N' near Post.
Quick Check
In a hospital database, what is the cardinality between 'Doctor' and 'Patient' if a doctor treats many patients and a patient can see multiple specialists?
Answer
Many-to-Many (M:N)
In advanced data modeling, Many-to-Many (M:N) relationships are complex because computers struggle to link them directly. In a school, many Students take many Classes. To solve this, we often use an Associative Entity (or junction table). Instead of a direct link, we create a 'Registration' entity that sits between them. This breaks the into two relationships: . This structure ensures that we can track specific data for that connection, such as the Grade a student received in a specific class.
Scenario: A 'Song' can appear on many 'Playlists', and a 'Playlist' contains many 'Songs'. 1. Identify Entities: Song, Playlist. 2. Identify Relationship: . 3. Create Associative Entity: 'Playlist_Entry'. 4. Map Cardinality: and . 5. Add Attributes: The 'Playlist_Entry' entity can now hold an attribute like .
Which visual shape represents an Entity in an ER Diagram?
A database tracks 'Department' and 'Manager'. If each department has only one manager and each manager runs only one department, what is the cardinality?
A Primary Key can have duplicate values as long as they are in different rows.
Review Tomorrow
In 24 hours, try to sketch an ERD for a 'Video Streaming Service' from memory. Can you identify the entities for Movies, Users, and Actors?
Practice Activity
Look at your favorite mobile app. Identify three entities and determine if the relationship between them is 1:N or M:N.