0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- Name the five steps of database design in order. from Lesson 0.1.4
- How many subsets does a set of n elements have? from Lesson 0.2.1
- What is the difference between a schema and an instance? from Lesson 0.1.3
1 · The Hook
The college asks you to design its database. Before tables, before SQL, you need a way to write down what the college talks about: students, courses, departments, hostels. You also need to record what is known about each one: a student has a roll number, a name, a CGPA.
The Entity–Relationship (ER) model is that way of writing things down. It uses three ideas only: entities, attributes and relationships. This lesson covers the first two.
2 · Predict First
Which of these are good candidates for entities in a college database, and which are better as facts about an entity: Asha, CGPA, the DBMS course, the student's phone number, the CS department?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
Predict First — the answer
Entities: Asha, the DBMS course, the CS department. Each is a separate thing the college wants to keep records about.
Facts about an entity (attributes): CGPA and phone number. They describe a student; on their own they are not things the college keeps a record of.
Entity
An entity is a thing in the real world that can be told apart from all other things and that the organisation wants to store data about. It can be physical (a student, a book) or conceptual (a course, a bank account, a job).
Asha (roll 1) is one entity. Bhavin (roll 2) is another.
Entity type and entity set
- An entity type is a group of entities with the same properties: STUDENT, COURSE, DEPARTMENT. It is part of the schema (it describes).
- An entity set is the collection of entities of a type stored at a moment: {Asha, Bhavin, Chirag, Diya}. It is an instance (it changes as students join and leave).
Many books (and GATE) use "entity set" for both meanings; the context tells which.
Attribute and domain
An attribute is a property that describes an entity: roll, name, dept, cgpa for STUDENT. Every entity of the type has a value for each attribute: Asha has roll = 1, name = Asha, dept = CS, cgpa = 9.1.
The domain (or value set) of an attribute is the set of values it may take: cgpa ∈ {real numbers from 0 to 10}, dept ∈ {CS, EE, ME, CE}. (This is the same "domain" as in Lesson 0.2.2.)
Mathematically, an attribute A of entity type E is a function from E to the domain of A: it gives each entity one value (or, for the special attributes of the next lesson, a set of values or no value).
Drawing them (Chen notation)
- Entity type: rectangle with the type name.
- Attribute: ellipse joined to its entity type by a line.
What decides "entity or attribute?"
Make something an entity if the organisation keeps several facts about it, or if other things are linked to it. DEPARTMENT has a building and a head, and both students and courses belong to departments: so it is an entity. A student's CGPA is a single value that describes the student: an attribute.
4 · Visual
An entity type (rectangle) with its attributes (ellipses).
| roll | name | dept | cgpa |
|---|---|---|---|
| 1 | Asha | CS | 9.1 |
| 2 | Bhavin | EE | 7.8 |
| 3 | Chirag | CS | 8.4 |
| 4 | Diya | ME | 6.9 |
The STUDENT entity set: one row per entity, one column per attribute.
5 · Worked Examples
Example 1 Easy
For a library database, name two entity types and two attributes of each.
Solution
BOOK (isbn, title) and MEMBER (member_id, name). Other answers are fine if each entity type is a "thing" the library keeps several facts about.
Example 2 Medium
Should "department" be an attribute of STUDENT or an entity type of its own, if the college stores each department's building and head of department?
Solution
An entity type. The college keeps several facts about each department (building, head), and other entity types (COURSE, FACULTY) also belong to departments. Keeping it as a student attribute would repeat the building and head for every student of that department.
Example 3 GATE
Entity type or entity set? (a) The definition "COURSE has cid, title, credits". (b) The four courses currently stored. Which one is part of the schema?
Solution
(a) entity type (schema). (b) entity set (instance). The entity type is part of the schema.
6 · GATE Traps
- An entity is one thing (Asha). The entity type is the category (STUDENT); the entity set is the current collection.
- An attribute describes an entity; it is not itself an entity, even if it has an interesting value.
- "Domain" means the set of allowed values, not the values currently stored.
- Ellipse = attribute; rectangle = entity type. Do not draw attributes as rectangles.
7 · Memory Hook
"Nouns are boxes, adjectives are bubbles." Things you keep records about become rectangles; the facts that describe them float around as ellipses.
8 · Connect the Dots
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1 · MCQ · 1 mark(s) — Entity
Which is an entity in a college database?
- (A) The domain {CS, EE}
- (B) The value 9.1
- (C) The word "name"
- (D) The student Asha
Q2 · MCQ · 1 mark(s) — Notation
In Chen notation an attribute is drawn as:
- (A) a triangle
- (B) a diamond
- (C) a rectangle
- (D) an ellipse
Q3 · MCQ · 1 mark(s) — Domain
The domain of an attribute is:
- (A) the set of values currently stored
- (B) the set of allowed values
- (C) the entity type it belongs to
- (D) the number of entities
Q4 · MSQ · 2 mark(s) — Entity type vs set
Which statements are true?
- (A) An entity set changes when a new student joins.
- (B) STUDENT is an entity type.
- (C) An entity type belongs to the schema.
- (D) An entity type and its entity set always have the same number of elements.
Q5 · MCQ · 1 mark(s) — Modelling choice
The college stores, for each hostel, its warden and its number of rooms, and students are allotted to hostels. HOSTEL should be:
- (A) the domain of an attribute
- (B) an attribute of STUDENT
- (C) a value
- (D) an entity type
10 · Rule Card
- Entity = distinguishable thing we store data about. Entity type = category (schema); entity set = current collection (instance).
- Attribute = property of an entity; domain (value set) = allowed values.
- Chen: rectangle = entity type; ellipse = attribute.
- Make it an entity if several facts are kept about it or other things link to it.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
entityentity typeentity setattributeattribute valuedomain (value set)Chen notation (rectangle, ellipse)
12 · Answer Vault
Reveal answers when you’re ready
Recall Warm-up
- Requirements → conceptual design (ER) → logical design (tables) → refinement (normalisation) → physical design.
- 2ⁿ.
- Schema: the description, rarely changes. Instance: the data at a moment, changes all the time.
Self-Test
Q1 Answer: (D) · 1 mark(s)
A distinguishable real-world thing the college stores data about.
- (A) is wrong: A set of allowed values.
- (B) is wrong: A value of an attribute.
- (C) is wrong: An attribute name.
Re-read: Lesson 1.1.1 — Entity, entity set, attribute, domain
Q2 Answer: (D) · 1 mark(s)
Rectangles are entity types; diamonds are relationships.
- (A) is wrong: Used for specialisation (Lesson 1.2.4).
- (B) is wrong: Relationship.
- (C) is wrong: Entity type.
Re-read: Lesson 1.1.1 — Entity, entity set, attribute, domain
Q3 Answer: (B) · 1 mark(s)
Value set = allowed values.
- (A) is wrong: Stored values are part of the instance.
- (C) is wrong: Not a domain.
- (D) is wrong: Not a domain.
Re-read: Lesson 1.1.1 — Entity, entity set, attribute, domain
Q4 Answer: (A) (B) (C) · 2 mark(s)
The type describes; the set is the current collection.
- (D) is wrong: A type is a description, not a collection.
Re-read: Lesson 1.1.1 — Entity, entity set, attribute, domain
Q5 Answer: (D) · 1 mark(s)
Several facts are stored about each hostel and students link to it.
- (A) is wrong: Not a value set.
- (B) is wrong: Would repeat warden and rooms for every student.
- (C) is wrong: It is a thing, not a value.
Re-read: Lesson 1.1.1 — Entity, entity set, attribute, domain