# Entities, Attributes and Relationships — Database Fundamentals

Source: https://www.skillbyai.com/en/database-fundamentals/e-basics

> Draw ER diagrams with attributes, relationships, cardinality and participation.

## Designing before building

The **entity-relationship (ER) model**, introduced by Peter Chen in 1976, describes data at the conceptual level. An **entity** is a real-world object (a student, a course); an **entity set** is a collection of similar entities, drawn as a rectangle. **Attributes** describe entities, drawn as ovals: **simple** (roll number) or **composite** (name made of first and last), **single-valued** or **multi-valued** (phone numbers, double oval), **stored** or **derived** (age derived from date of birth, dashed oval), and the **key attribute** (underlined). A **relationship** connects entities (a student *enrols in* a course), drawn as a diamond, and may have its own attributes (the grade belongs to the enrolment, not to the student or the course). **Cardinality** constrains how many entities participate: **one-to-one**, **one-to-many** or **many-to-many**. **Participation** is **total** (every entity must take part, double line: every course must belong to a department) or **partial** (single line: not every student must hold a scholarship).

## A small ER diagram

Entity sets, attributes and a many-to-many relationship with its own attribute.

![Two rectangles connected through a diamond, each rectangle surrounded by a few ovals, and one oval attached to the diamond itself.](assets/figures/database-fundamentals/section-2-map.svg) — Figure 2.1 — Entities, attributes and a relationship with an attribute.

## Describing a university in ER terms

Textual notation for the diagram you would draw.

```text
entity STUDENT   (roll_no [key], name (first, last) [composite], phones [multi-valued],
                  dob, age [derived])
entity COURSE    (course_id [key], title, credits)
entity DEPARTMENT(dept_id [key], name)

relationship ENROLS     STUDENT M --- N COURSE      attributes: semester, grade
relationship OFFERS     DEPARTMENT 1 --- N COURSE   COURSE participation: total
relationship HEADS      PROFESSOR 1 --- 1 DEPARTMENT

reading: a student enrols in many courses; a course has many students;
         every course is offered by exactly one department
```

## Put attributes where they belong

A grade is not a property of a student (they have many grades) or of a course; it describes one student's enrolment in one course. Attributes of a relationship are a frequent exam and design question.

**Quiz:** In an ER diagram, how is a multi-valued attribute such as phone numbers drawn?

- [ ] A dashed oval
- [ ] A diamond
- [x] A double oval
- [ ] An underlined rectangle

*Answer:* A double oval. Multi-valued attributes use a double oval; derived attributes use a dashed one.
