Entities, Entity Sets and Attributes

The ER Model · 25 min

Core CS · DBMS

Draw the kind of thing, not the thing

An entity is Asha. STUDENT is the rectangle the college draws once for all forty thousand of them. This lesson takes one requirement sentence apart into six attributes, and shows which two of the six never become columns at all.

Turn one requirement sentence into a diagram
A rectangle is a kind of thing, not a thing. It does not change when a student enrols, when one graduates, or when the college has none left. The entity set does all three.

01 The idea

The rectangle is a kind, the set is today’s contents

The ER model has exactly one job before relationships enter the picture: decide what kinds of thing the database stores facts about, and what facts it stores about each kind. The kinds become rectangles. The facts become ovals hanging off them. Everything difficult about this topic is one question asked in different clothes, which is whether a noun in the requirement is a thing or a fact about a thing.

Start with a college. Asha Menon, roll number 21CS007, is a thing you can point at. So are Ravi and Meera. Each of them is an entity: something distinguishable that the database keeps facts about. The college does not draw a rectangle for Asha, one for Ravi and one for Meera. It draws one rectangle called STUDENT, because all three are the same kind of thing and the same list of facts applies to each. That rectangle is the entity type, and the three of them together are the entity set.

The exam question is almost always the gap between those last two, because only one of them moves. Admit a student and the entity set grows by one. Graduate a batch and it shrinks. Delete every row in the table and the entity set becomes empty, and the entity type is still exactly what it was, because the type is a definition and definitions do not depend on how many things currently satisfy them. The relational parallel is worth holding on to: the entity type is the CREATE TABLE, the entity set is what SELECT * returns today, and an entity is one row of that result.

Draw the rectangle for the kind of thing, never for the thing. STUDENT is one rectangle whether the college has three students or forty thousand, and every attribute you hang off it has to be a question you could ask of every one of them.
EntityOne distinguishable thing the database keeps facts about. Asha Menon, roll number 21CS007, is an entity. Books that reserve the word for the definition call this an entity instance instead.
Entity typeThe definition: a name plus the list of attributes every entity of that kind has. This is what the rectangle means. STUDENT is an entity type; it is not any particular student.
Entity setEvery entity of one type in the database at this moment, also called the extension. It changes on every admission and every graduation. The type it belongs to does not.

02 Worked example

From three students to one rectangle

Here is the entity set the college holds this morning. Three entities, one type. Read the rows as three things in the world, not as a table yet, and notice that Asha’s phone cell already holds two values at once.

Roll noNameAddressPhoneDate of birth
21CS007Asha Menon12, MG Road, Bengaluru 5600019876543210  /  080412345672004-08-19
21CS012Ravi Kumar8, Park Lane, Hyderabad 50008494400112232003-11-02
21CS019Meera Nair4, Lake View, Kochi 68201698475566772005-01-30

Three rows, and every column is a question you can ask of all three. That is what makes them one entity set rather than three unrelated records. Now climb the ladder from the girl in the classroom to the shape on the whiteboard. The highlighted node is the one students skip, and it is the one the exam asks about.

1 · A thing in the worldAsha, sitting in the third-year CSE classroom. Not data at all yet
2 · One entitythe facts the college keeps about her: 21CS007, a name, an address, two phones, a date of birth
3 · One entity typeSTUDENT: a name and a list of attributes. The same rectangle for 3 students or 40,000
4 · One entity setthe three rows above. Grows on every admission, shrinks on every graduation, can be empty
5 · One diagrama rectangle with ovals on it, and the shape of each oval says what kind of fact it is

Nodes 3 and 4 are the whole of the definition question. Node 3 is a sentence about what a student is; node 4 is a count of who there are. An interviewer who asks “entity or entity set?” is checking whether you can put an operation on the right side of that line: admit a student changes node 4 and leaves node 3 untouched, while start recording blood group changes node 3 and forces every entity in node 4 to answer a new question.

Node 5 is where the notation lives. The requirement sentence the college started from was: the roll number, the name, the address, the phone numbers, the date of birth; and the office prints the age on the ID card. Six facts, and five different ways of drawing an oval, because they are not all the same kind of fact.

[ S T U D E N T ]                   entity type: a rectangle    |    +-- ( _roll_no_ )               key: underline the name inside the oval    +-- ( name )                    simple, single-valued: a plain oval    +-- ( dob )                     stored: a plain oval    +-- (- age -)                   derived from dob: a dashed oval    +-- (( phone ))                 multivalued: a double oval    +-- ( address )                 composite: an oval with child ovals            +-- ( door_no )            +-- ( street )            +-- ( city )            +-- ( pin ) -- 1 rectangle · 10 ovals · 1 underlined · 1 dashed · 1 doubled

Count the ovals with your finger and you get ten, not six: address contributes five on its own, because a composite attribute is drawn as a parent with its parts attached. That count is the first thing to check on your own drawing, and it is the number the console in section 04 arrives at one step at a time.

Those five treatments are not decoration. The plain oval costs you nothing, the underline costs you a PRIMARY KEY clause, the child ovals cost one column each, and the two unusual shapes — the double oval and the dashed one — are the expensive ones, because they are the only two that do not end up as columns of STUDENT at all: one buys a whole second table, the other buys nothing. These are Chen’s shapes, which is what exams and textbooks draw; the crow’s-foot tools you will meet at work list attributes inside the rectangle and have no shape for multivalued or derived at all, so the two expensive decisions stop being visible on the diagram and show up only in the schema. The next section is that sentence made precise.

03 Mechanics

Eight labels, and the one test that decides each

Attribute kinds are not a list to memorise; they are four independent questions you ask of every attribute, and most attributes come back with two or three labels. Simple against composite is one question, single-valued against multivalued is a second, stored against derived is a third, and key against non-key is a fourth. The middle column is the test. The last column is what the label actually costs you, and it is the column interviewers push on.

LabelThe test that decides itIn our STUDENTChen notationWhat it becomes in SQL
Simple (atomic) Can it be split into parts somebody would query separately? No. roll_no, name, dob, city plain oval one column
Composite Yes, and each part is meaningful on its own and has its own domain. address = (door_no, street, city, pin) an oval with child ovals attached one column per leaf; the parent itself is never a column
Single-valued At most one value for one entity at one instant. roll_no, name, dob, address plain oval one column
Multivalued Two values true for the same entity at the same instant phone = {9876543210, 08041234567} double oval its own table, keyed on the parent key plus the value
Derived You could delete it and get it back with no new information age, from dob and the current date dashed oval no column you maintain: a view, an expression, or a generated column
Stored The attribute a derived one reads. Nothing else in the database produces it. dob plain oval one column
Key Distinct across every entity of the type, in every legal state, not just today. roll_no the name underlined inside its oval PRIMARY KEY, or UNIQUE NOT NULL
Complex Composite and multivalued nested inside each other, to any depth. {contact({phone(std_code, number)}, address(...))} braces for multivalued, parentheses for composite a table for every pair of braces

Now the same six attributes as a schema. Nothing here is a new idea; every line is one of the labels above, spent. Read the comments as the bill.

CREATE TABLE student (  roll_no  CHAR(7)     PRIMARY KEY,      -- key: distinct for all legal data, never NULL  name     VARCHAR(60) NOT NULL,         -- simple, single-valued  door_no  VARCHAR(10),                   -- \  street   VARCHAR(60),                   --  | composite address, one column per leaf,  city     VARCHAR(40),                   --  | so "students in Bengaluru" is a lookup  pin      CHAR(6),                       -- / six characters declared; "digits only" is not  dob      DATE                            -- stored, and left nullable. age is deliberately absent);CREATE TABLE student_phone (                -- the multivalued attribute gets a table  roll_no  CHAR(7) REFERENCES student(roll_no),  phone    VARCHAR(15),  PRIMARY KEY (roll_no, phone)          -- the pair: no number twice for one student);CREATE VIEW student_age AS                   -- derived: computed on read, never stored  SELECT roll_no, name, date_part('year', age(dob)) AS age FROM student;

The composite attribute cost four columns and no tables. Lines 4 to 7 are the four leaves of address. There is no address column, because a composite attribute exists only in the diagram; what reaches the table is its parts. Keep it as one string instead and counting students by city becomes a substring search that no index helps and that a street named “Bengaluru Road” quietly corrupts.

The multivalued attribute cost a whole table. Line 10 exists because first normal form says a cell holds one value, and Asha has two phone numbers that are both true right now. Line 13 makes the pair the key, so the same number cannot be recorded twice for one student. Columns named phone1 and phone2 are the alternative, and they fix a maximum you will regret and turn “who owns this number” into a search across however many columns somebody happened to create.

The derived attribute cost nothing, as long as you do not store it. Line 16 computes age on read. Asha was born on 19 August 2004: on 27 July 2026 she is 21, and on 19 August 2026 she is 22, with no insert and no update in between. A column that changes without a write is a column that will be wrong. The expression is vendor-flavoured — MySQL writes it TIMESTAMPDIFF(YEAR, dob, CURDATE()) — but the placement is not.

The domain, which Elmasri calls the value set, is the set of values an attribute is allowed to take. The domain of pin is the six-digit strings, the domain of dob is dates and not any date, and the domain of a mark is the integers 0 to 100. In SQL you write the coarse half as the column type and the rest as a CHECK. Line 7 declares six characters and stops there, so “ABC123” is still accepted: whatever you leave out of both halves is a value the database will take without complaint.

NULL is not in the domain. It is a marker meaning there is no value in this cell, and the marker carries three different meanings that it cannot tell apart. Three students, two extra columns, three blanks, one of each meaning:

Roll nodobhostel_roomlandline
21CS0072004-08-19NULL · not applicable08041234567
21CS012NULL · missingH-20404023456789
21CS0192005-01-30H-118NULL · unknown

Not applicable: Asha is a day scholar, so there is no hostel room to record and there never will be while she is a day scholar. Missing: Ravi has a date of birth; the admission form was left blank, so the value exists in the world and not in the database. Unknown: nobody can say whether Meera’s house even has a landline, so you cannot call the value missing without first claiming it exists. Elmasri splits the second and third slightly differently from this, and some syllabi name the third “not recorded”; every version of the list has three buckets, and the first bucket is the one that carries marks, because it is the only one that says the design is wrong rather than the data incomplete.

Those three blanks change what queries return, and this is where the topic stops being vocabulary. Against exactly the three rows above: COUNT(*) is 3 and COUNT(dob) is 2, because aggregates skip NULLs. WHERE hostel_room = 'H-204' returns 1 row and WHERE hostel_room <> 'H-204' returns 1 row, which is 2, not 3. Asha’s row is in neither, because comparing anything with NULL gives unknown rather than true or false, and WHERE keeps only the rows where the condition is true. IS NULL is the only operator that inspects the marker instead of comparing to it, and it finds her.

Every attribute gets a label on four independent axes, and only two of the labels take the attribute out of the columns of its own table: multivalued moves it into a second table, and derived leaves no column at all. The rest decide how many columns and which constraints, not where the data lives.

05 Cheat sheet

Every term on one card

Thirteen terms, and for each one the mistake that loses the mark. The right-hand column is the useful half: nobody is tested on whether you can recite a definition, only on whether you can apply it to a noun you have not seen before.

TermWhat it means, in one lineThe trap
Entityone thing you can point at: Asha, roll number 21CS007calling the rectangle an entity
Entity typethe definition: a name and a list of attributes. This is the rectangleSilberschatz says "entity set" for this too
Entity setevery entity of that type in the database right now, also called the extensionit changes on every admission; the type does not
Simple (atomic)not divisible into parts anybody queries separately"simple" and "atomic" are the same word here
Compositedivides into parts that are separately meaningful, each with its own domainstored as one string, "count by city" becomes a text search
Single-valuedat most one value for one entity at any one instanta value that changes over time is still single-valued
Multivaluedtwo or more values true for one entity at the same instantphone1, phone2, phone3 fixes a maximum you will regret
Derivedrecomputable from stored data, or from stored data and the clockstored, it is wrong from the morning of the birthday
Storedthe attribute a derived one reads; nothing else produces ita measured value that changes is stored, not derived
Key attributedistinct for every entity of the type, in every legal stateread off today's rows instead of off the rule
Complexmultivalued and composite nested: braces and parenthesesnotation only; a relational cell cannot hold one
Domain (value set)the set of values the attribute is allowed to takethe column type is the coarse half; the rest is a CHECK
NULLno value here: not applicable, missing, or unknownNULL = NULL is unknown, so use IS NULL
Three words, one distinctionAn entity is a row, an entity type is the CREATE TABLE, and an entity set is what SELECT * returns today. Say that sentence and you have answered the most asked question in this topic, along with its follow-up about what happens when the table is empty. The type survives an empty table; the set is the empty table.
Only two shapes cost anythingEvery attribute is a plain oval except four, and only two of those four take the attribute out of the STUDENT table. The double oval becomes a second table because a cell holds one value; the dashed oval becomes no column at all. The underline adds a PRIMARY KEY clause and the child ovals add columns, but neither adds a table.
NULL is not zero and not an empty stringZero is a value, '' is a value, NULL is the absence of one, and the three behave differently in every comparison and every aggregate. The exception worth naming is Oracle, which stores the empty string as NULL, so on Oracle a blank field and a missing one are the same thing and two of the three meanings collapse into one.

06 Where & why

What each label costs you in a real database

Attribute kinds sound like diagram vocabulary until you try to declare one. Every real system supports some of them directly, refuses others, and disagrees with its neighbours about NULL. These four are where the disagreements are, and naming one of them in an interview is the difference between having drawn ER diagrams and having built a schema.

PostgreSQL · MySQL
Derived is a generated column, right up until it is not

Both let you declare a derived attribute as a generated column, so the database recomputes it: GENERATED ALWAYS AS (...) STORED in PostgreSQL from version 12, VIRTUAL or STORED in MySQL. Age is the one that will not compile, because the expression has to be deterministic and the current date is not. That is why age lives in a view. SQL Server does allow a non-deterministic computed column, but it will neither persist nor index it.

PostgreSQL
Composite and multivalued as one column

PostgreSQL has composite types (CREATE TYPE address AS (...)) and array columns (text[]), so both shapes can live inside a single column. Most schemas still give the multivalued attribute its own table, because an array cannot carry a foreign key, cannot be constrained value by value, and gives you no place to record when each phone number was added.

SQL Server
The key attribute is the one that can never be NULL

PRIMARY KEY implies NOT NULL everywhere, which is the ER rule enforced. UNIQUE is where vendors split: SQL Server allows exactly one NULL row in a unique column because it treats NULLs as equal, while PostgreSQL, MySQL and SQLite allow many because two unknowns are not known to be equal. PostgreSQL 15 added UNIQUE NULLS NOT DISTINCT if you want the other behaviour.

SQLite
The domain is only as real as the CHECK you write

SQLite uses type affinity, not type enforcement, so a column declared INTEGER will store the text 'hello' without complaint. The attribute’s domain exists only if you add a CHECK or declare the table STRICT, available since 3.37. It is the clearest demonstration that a domain is a rule you write down, not a property the column has by being named.

Say the cost, not the shape. “Phone is multivalued” is a label anybody can read off a diagram. “Phone is multivalued, so it is a second table keyed on roll number and the number itself, because a cell holds one value and phone1 and phone2 fix a maximum” is the answer, and it takes one more breath.

07 Interview questions

What they actually ask

This is the opening of almost every ER round, and the first two questions are definitions the interviewer expects you to get wrong in a specific way. Answer with an example from a system you have built, not from a textbook college, and the round moves on to relationships faster.

What is the difference between an entity and an entity set?
An entity is one thing the database keeps facts about; an entity set is all the entities of one kind that are in the database right now. Asha, roll number 21CS007, is an entity, and the students on the college’s books this morning are the entity set she is part of. That set changes on every admission and every graduation, and can be empty, while the rectangle labelled STUDENT stays exactly as it was. Books that reserve the word entity for the definition call the individual thing an entity instance instead, so name the convention you are using and the interviewer will follow it.
Entity type or entity set? They sound like the same thing.
The type is the definition and the set is the contents. An entity type is a name plus a list of attributes, which is exactly what the rectangle in the diagram means; the entity set is every entity of that type at this moment, which Elmasri also calls the extension. The names are genuinely not settled: Silberschatz and Korth use entity set for both the definition and the collection and do not introduce the term entity type at all, while Elmasri separates them. Most Indian university syllabi and placement question banks use the Elmasri terms, so answer in those and mention the other in a clause.
What makes an attribute a key attribute?
Its values are distinct for every entity of that type in every legal state of the database, not just in the rows you can see. Roll number is a key because the college guarantees it never reissues one; email is not a key just because every student in the table today happens to have a different address. A key is a rule, so you argue it from the rules and never from sample data. In the diagram you underline the attribute name inside its oval, and an entity type may have more than one such attribute.
What is a composite attribute, and what happens to it in a table?
One whose value breaks into parts that are separately meaningful. Address is composite because door number, street, city and PIN each have their own domain and their own use. It is drawn as an oval with child ovals hanging off it, and in a table it becomes one column per leaf — there is no column for the parent, because the parent exists only in the diagram. Keep it as one string and counting students by city stops being a lookup and becomes a substring search.
What is a multivalued attribute?
One that has two or more values for the same entity at the same instant. Asha has two phone numbers now, not one now and one later, so phone is multivalued and gets a double oval. The reason it matters is that first normal form says a cell holds one value, so a multivalued attribute cannot be a column of the parent table at all. Compare it with a single-valued attribute that merely changes over time, like the hostel room a student is allotted: that is still one value at any instant, so it stays a column.
Why should age not be a column?
Because it is derived: it is date of birth read against the current date, so it changes with no insert and no update to blame. Store it and the row is wrong from the morning of the student’s birthday until whatever refreshes it next runs. Date of birth is the stored attribute, and age belongs in a view or in the query. The general rule is that a value you can recompute from what you already hold is a second copy, and second copies are free to disagree with the first.
Something changes over time. Does that make it derived?
No, and this is the confusion the examiner is testing. A student’s address changes when the family moves and is still stored, because the only way to get the new one is to be told it — delete the value and it is gone. Age also changes, but deleting it costs nothing, because date of birth and the calendar reproduce it exactly. The test is not whether a value moves; it is whether you could delete it and get it back with no new information.
What is the domain of an attribute?
The set of values the attribute is allowed to take, which Elmasri also calls its value set. The domain of a PIN is the six-digit strings, the domain of a mark is the integers 0 to 100, and the domain of a date of birth is dates but not every date. In SQL you write the coarse half as the column type and the rest as a CHECK constraint, and whatever you leave out of both is a value the database will accept without complaint.
What does NULL actually mean?
It is a marker saying there is no value in this cell, and it carries three meanings the marker itself cannot tell apart. Not applicable, where the attribute does not apply to this entity at all, such as a hostel room for a day scholar. Missing, where a value exists in the world and was never recorded, such as a date of birth left blank on the form. Unknown, where you cannot even say whether a value exists, such as whether a house has a landline. Textbooks split the last two slightly differently; every version has three buckets, and only the first one says the design is wrong rather than the data incomplete.
I ran one query for room = H-204 and another for room &lt;&gt; H-204, and together they returned fewer rows than the table has. Why?
Because any comparison with NULL evaluates to unknown rather than true or false, and WHERE keeps only the rows where the condition is true. A row whose room is NULL fails both tests, so it appears in neither result and the two counts do not add up to the table. IS NULL and IS NOT NULL are the only operators that inspect the marker instead of comparing to it. The same rule is why COUNT(room) can be smaller than COUNT(*).
Can a key attribute be NULL?
No. A key has to identify an entity and NULL is the absence of a value, so a NULL key identifies nothing. SQL enforces it: PRIMARY KEY implies NOT NULL in every mainstream database. UNIQUE is where vendors split — PostgreSQL, MySQL and SQLite allow many NULL rows in a unique column because two unknowns are not known to be equal, while SQL Server allows exactly one. If you mean a key, declare it UNIQUE NOT NULL and the difference stops mattering.
When would you actually use any of this?
For about two hours at the start of a project, and then never again as a diagram. What survives is the schema, and two of the decisions in this lesson are the expensive ones to reverse once there is data: a multivalued attribute you stored as phone1 and phone2, and a derived value you stored as a column. Everything else is a column you can widen or rename in an afternoon. That is the honest reason the two hours are worth it, and it is a better answer than calling ER diagrams good documentation.

08 Practice problems

Six to work through

For every one, ask the four questions in order before you write a label: can one entity have two of these at the same instant, can it be split into parts somebody queries, could you delete it and recompute it, and is it distinct for every entity in every legal state. Labelling first and justifying afterwards is how people end up calling a measurement derived.

Eight phrases, five labels

Easy
Label each of these eight phrases from a college’s documents as an entity, an entity type, an entity set, an attribute, or an attribute value: (a) STUDENT; (b) Asha Menon; (c) roll number; (d) 21CS007; (e) the 4,182 students currently enrolled; (f) date of birth; (g) 19 August 2004; (h) the rectangle drawn on the whiteboard and labelled COURSE.
Follow-up
Three of the eight get a different label depending on which textbook’s convention you follow. Name all three, name the book that disagrees, and say which single pair of labels is the distinction this whole topic is tested on.
Show the hint
For each phrase ask whether you could point at it, count it, or ask it as a question. Only one of those three verbs works for any given phrase.

Which NULL is it?

Easy
A STUDENT table has five blank cells, none of them the three blanks in section 03. Label each as not applicable, missing, or unknown: (a) spouse_name for an unmarried student; (b) blood_group for a student who left that line of the medical form empty; (c) second_language for a student where the office cannot say whether the course even offers one to her batch; (d) scholarship_amount for a student who never applied for a scholarship; (e) phone for a student who gave the college no phone number at all.
Follow-up
One of the five is not a NULL in a correct design, and it is not because the value is known. Say which, say what the correct design stores instead, and say which attribute label from this lesson forced that design.
Show the hint
For each blank ask, in this order, whether a value could exist for this entity, whether one does exist, and whether the attribute is even a column of this table.

Redraw it, then count

Medium
Take the STUDENT requirement from this lesson and add three sentences: a student may hold more than one email address; the office prints the student’s initials on the ID card; and the guardian’s address is recorded, with door number, street, city and PIN. Redraw the diagram and report five numbers: total ovals, double ovals, dashed ovals, underlined attributes, and relational tables.
Follow-up
Exactly one of the three additions changes the table count and the other two do not, and the five numbers are the only way to see which. Say which one, and say what would have to change about a second addition to make it change the count too.
Show the hint
Count the ovals leaf by leaf first and only then ask, of each new attribute, whether one student can have two of them at the same instant.

Seven attributes, several labels each

Medium
A hospital records, for each patient: patient id, full name, the wards the patient has been admitted to, blood group, height in centimetres, weight in kilograms, and body mass index. Give every label from this lesson that applies to each of the seven — most get two or three — and name the one that a correct design recomputes instead of recording, and the one that can never be NULL.
Follow-up
Three of the seven are numbers that change over time, and only one of those three is a design problem. Say which three, say which one is the problem, and say what the requirement would have to say instead for the ward attribute to stop being multivalued.
Show the hint
For each attribute ask, in this order: can one patient have two at the same instant, can it be split into parts somebody queries, and could you delete the value and get it back with no new measurement.

The nightly job and the birthday

Medium
The office stored age as an INT column and refreshes every row with a job that runs at 02:00 each night. Asha was born on 19 August 2004. Give the stored value and the true value at each of these three moments: 27 July 2026 at midday; 19 August 2026 at 00:30; 19 August 2026 at 23:00. Then describe what a week of failed jobs looks like to somebody reading the table.
Follow-up
At exactly one of the three moments the stored value is correct for a reason that has nothing to do with the job having run. Say which moment, and say what that reason implies about how often the job is actually earning its place.
Show the hint
Write down when the job last ran before each moment, and only then work out what it would have computed at that time.

Flatten a complex attribute

Hard
Take the complex attribute {contact({phone(std_code, number)}, address(door_no, street, city, pin))} on STUDENT: a student has many contacts, each contact has many phones and exactly one address. Turn it into relational tables. Give every table, every key, and the exact rows that hold Asha’s two contacts when her home contact has two phone numbers and her guardian contact has one. Then name the two attribute labels from this lesson that braces and parentheses cannot express at all, and say what those two have in common.
Follow-up
Two of your tables need a composite key, and one of those is only a key because of a rule the requirement never states. Find it and write the missing sentence out in full.
Show the hint
Work outward from the innermost pair of brackets, and at each level ask only one question: can this entity have two of what is inside.