Entities, Attributes and Relationships
Turn a plain-language description of a business into entities, attributes and relationships, and recognize composite, multivalued and derived attributes.
Welcome back!
Step 1 of 12Learn
From interview notes to a model
Design starts with listening, not with tables. Here's what the bookstore owner says in an interview:
"We sell books online. Each book has a title, an ISBN, a price and a publication year, and can have several authors. Customers create an account with their name, email and shipping address, and they place orders. An order has a date and contains one or more books, each with a quantity. We also keep the publisher of each book."
A classic technique is to underline the nouns and verbs. Important nouns that have their own data and identity become entities: Book, Author, Customer, Order, Publisher. Nouns that merely describe something become attributes: title, ISBN, price, email, date. Verbs connecting entities become relationships: a customer places an order, an order contains books, an author writes books, a publisher publishes books.
Not every noun is an entity. "We" is the business itself. "Account" here is just the customer record. And "quantity" is interesting: it isn't a property of a book or of an order alone, but of a particular book within a particular order. Spotting facts like that early saves trouble later. In this module you'll turn notes like these into a diagram and then into tables.
Step 2 of 12Practice · Sort into groups
Using the bookstore interview, classify each noun.
Tap an item, then tap its group (or drag it there).
Step 3 of 12Diagram
The bookstore interview as a first model
Entities (the things) branch into the attributes that describe them. Tap an entity to see why it is a thing and not a column.
Tap a shape with to see more.
- Bookstore
- Customer
Many facts about each one, and many orders refer to it.
- Book
- Order
- Author
A book can have several authors, so author cannot be a single column of book.
- name, email
- shipping address
- title, ISBN
- price, year
- order date
- author name
Step 4 of 12Learn
Entities, instances and identifiers
An entity type (often just "entity") is a category of thing the organization needs to remember, such as Customer. Each specific customer, like Ana Ruiz, is an instance. In the final database, an entity type usually becomes a table and each instance becomes a row.
How do you decide whether something deserves to be an entity rather than an attribute? Ask three questions:
- Does it have facts of its own? A publisher has a name, a country and a website, so it is more than a label on a book.
- Is it shared by many other things? Many books share one publisher. Storing the publisher's details in every book row would repeat them.
- Does the business need to track it independently? The shop may want to list publishers it works with, even ones with no books in stock right now.
If the answers are mostly yes, make it an entity. If it's just a single value describing something else, keep it as an attribute. Color, for instance, is usually an attribute of a product, unless the business manages a palette of colors with codes, names and suppliers.
Every entity needs an identifier: an attribute or combination whose value is unique for each instance. It will become the primary key. Entities that can only be identified through another entity, such as line 3 of order 1042, are called weak entities.
Step 5 of 12Practice · What would you do?
What would you do?
The bookstore stores "genre" as a text attribute on each book (values like "Mystery" or "Science fiction"). The owner now wants each genre to have a description, a display color on the website, and a staff member responsible for it. What should the designer do?
Step 6 of 12Learn
Kinds of attributes
Attributes come in several flavors, and each one maps to tables differently.
- Simple attributes hold one indivisible value: price, ISBN.
- Composite attributes are made of parts: an address has street, city, postal code and country. In tables you usually store the parts as separate columns, so you can search or sort by city.
- Multivalued attributes can hold several values for one instance: a customer may have several phone numbers, a book several keywords. A cell can't hold a list, so a multivalued attribute becomes its own table, with one row per value.
- Derived attributes can be calculated from other data: a customer's age from their birth date, an order's total from its lines. Usually you don't store them, because a stored copy can go out of date. Compute them in queries instead, unless performance demands otherwise.
- Key attributes form the identifier.
A common early mistake is to treat a multivalued attribute as simple: a column called authors containing "Smith, Lee, Patel." That makes it impossible to find all books by Lee reliably, to count authors, or to enforce that each author exists. Spotting multivalued attributes in the conceptual model prevents this.
Step 7 of 12Practice · Match the pairs
Match each bookstore attribute to its kind.
Tap an answer, then tap the place where it belongs (or drag it there).
- A customer's several phone numbers
- Shipping address with street, city and postal code
- An order's total, computed from its lines
- A book's publication year
Step 8 of 12Practice · Diagram
Attribute kinds and where they end up
Which kind is the only one that needs a separate table?
Tap the shape that answers the question, then press Check.
- Attribute
- Simple
One column: price DECIMAL(8,2).
- Composite
Split into one column per part: street, city, postal_code, country.
- Multivalued
Its own table: customer_phone(customer_id, phone).
- Derived
Usually not stored at all; computed in queries (an order total).
- Key
Becomes the primary key, or gets a UNIQUE constraint.
Step 9 of 12Learn
Relationships and their degree
A relationship is a meaningful association between entities, usually named with a verb: Customer places Order. Like entities, relationships have instances: "Ana placed order 1042" is one instance of places.
The degree of a relationship is the number of entity types involved:
- Binary relationships involve two entities and are by far the most common: Customer places Order, Author writes Book.
- Unary (or recursive) relationships connect an entity to itself: an Employee manages other Employees; a Course is a prerequisite of another Course.
- Ternary relationships involve three at once: a Doctor prescribes a Medication to a Patient. Splitting this into separate binary relationships can lose information about which doctor prescribed which medication to whom.
Relationships can carry attributes of their own when a fact belongs to the association rather than to either entity. Quantity in the bookstore is the textbook case: it describes a book in an order. The date an employee started managing another employee is another example.
Name relationships clearly and read them in both directions: "a customer places orders" and "an order is placed by a customer." Reading both ways is the first step toward the cardinality questions of the next lesson.
Step 10 of 12Compare
Relationship degree at a glance
| Aspect | Unary | Binary | Ternary |
|---|---|---|---|
| Entity types involved | 1 | 2 | 3 |
| Example | Employee manages Employee | Customer places Order | Supplier ships Part to Project |
| How common | Occasional | The vast majority | Rare |
| Typical table form | FK to the same table | FK, or a junction table for M:N | One table with three FKs |
Step 11 of 12Note
Step 12 of 12Practice · Choose one
A university records which instructor teaches which course in which semester, and the same instructor can teach different courses in different semesters. Which kind of relationship captures this most directly?
Lesson complete!