Drawing and Reading ER Diagrams
A complete guide to ER notation and a repeatable eight step method for turning a written requirement into a correct, readable ER diagram.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
An ER diagram is the picture of a design, drawn before any table exists so that the people who asked for the system can check it. Everything in this phase so far now appears in one notation.
The complete notation
| Symbol | Means |
|---|---|
| Rectangle | Entity type |
| Double rectangle | Weak entity type |
| Ellipse | Attribute |
| Underlined text in an ellipse | Key attribute |
| Dashed underline | Partial key of a weak entity |
| Double ellipse | Multivalued attribute |
| Dashed ellipse | Derived attribute |
| Ellipse with child ellipses | Composite attribute |
| Diamond | Relationship type |
| Double diamond | Identifying relationship |
| Single line | Partial participation |
| Double line | Total participation |
| 1, N, M on a line | Cardinality ratio |
| Text beside a line | Role name |
| Triangle marked ISA | Generalisation or specialisation |
An eight step method
- Read the requirement and underline every noun. Nouns are candidate entities and attributes.
- Underline every verb. Verbs are candidate relationships.
- Split the nouns into entities and attributes using the four tests from the entities note.
- Choose a key for each entity type, and mark weak entities where no key exists.
- Add relationships between entity types, named with verbs.
- Decide cardinality for each relationship by asking the question in both directions.
- Decide participation by asking whether every entity must take part.
- Attach attributes, placing any that depend on the combination on the relationship itself.
Step 6 has a fixed script. Ask: can one A relate to many B? and then can one B relate to many A? Two yes answers means many to many. One yes means one to many, and the many side is the one that answered yes.
Worked example
Requirement. A college has departments, each with a code, a name and exactly one head of department. Every student belongs to exactly one department and has a roll number, a name, a date of birth and possibly several phone numbers. Courses have a code, a title and credits, and are offered by a department. Students enrol in courses and receive marks for each. Some students take a course more than once, in different semesters.
STEP 1-2 nouns: college, department, code, name, head,
student, roll number, date of birth, phone,
course, title, credits, marks, semester
verbs: belongs to, offers, enrols, heads
STEP 3 entities: DEPARTMENT, STUDENT, COURSE
attributes: everything else
college is the whole mini world, not an entity
STEP 4 keys: dept_code, roll_no, course_code
STEP 5 relationships:
DEPARTMENT ---- HAS ---- STUDENT
DEPARTMENT ---- OFFERS ---- COURSE
STUDENT ---- ENROLS ---- COURSE
STEP 6 can one department have many students? yes
can one student belong to many departments? no
-> 1:N, many side is STUDENT
can one student enrol in many courses? yes
can one course have many students? yes
-> M:N
STEP 7 every student must belong to a department -> TOTAL
a department may have no students yet -> partial
a student may have enrolled in nothing -> partial
STEP 8 marks and semester depend on the PAIR
-> attributes of ENROLS
phone is multivalued -> double ellipse
THE DIAGRAM
(dept_code) (dept_name) (roll_no) (dob)
/ | /
+--------------+ +-----------+ ((phone))
| DEPARTMENT |====< HAS >---| STUDENT |---/
+--------------+ 1 N +-----------+
| |
| 1 | M
< OFFERS > < ENROLS >--( marks )
| | \_( semester )
| N | N
+--------------+ |
| COURSE |--------------------+
+--------------+
(course_code) (title) (credits)The last requirement sentence
Some students take a course more than once, in different semesters. That means the pair roll_no and course_code is not unique on its own, so semester must be part of the key of the enrolment. This is the signal described earlier: the relationship is behaving like an entity, and its key is ( roll_no, course_code, semester ). Missing this sentence produces a design that silently loses the second attempt.
Common mistakes
- Modelling the whole system as an entity. The college is the mini world, not an entity type.
- Attaching relationship attributes to an entity. Marks on STUDENT is wrong.
- Guessing cardinality. Ask the question in both directions, every time.
- Leaving participation unmarked. The diagram is then incomplete, and the
NOT NULLdecisions cannot be made. - Overcrowding one diagram. Split a large model into subject areas rather than producing something unreadable.
- Naming relationships with nouns. Use verbs so the diagram reads as sentences.
Exam and interview questions
- List every ER symbol and what it represents.
- Describe a method for producing an ER diagram from a written requirement.
- How do you determine the cardinality of a relationship? State the exact questions.
- Where do you attach an attribute that depends on two entities?
- What does it tell you when a many to many relationship needs a third attribute in its key?
Practice
- Draw an ER diagram for a bus service with routes, buses, drivers and trips.
- Take the college example and add a rule that a course may have prerequisite courses. Show the relationship and its role names.
- Write the eight steps from memory and apply them to a gym membership system.
Conclusion
Nouns become entities and attributes, verbs become relationships, cardinality is settled by asking the question both ways, and participation decides what is compulsory. Follow the eight steps in order and the diagram will be complete rather than merely plausible.