# Relations

A **relational database** contains multiple tables/relations.

A **relation** is a set of tuples where each attribute is part of a domain.

Relations are represented as tables.

The columns of the table represent attributes of the relation and the rows/tuples represent the relationship between the entities i.e. the values for the relation.

The following is an example of a relation:

![](https://1736932896-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5-0RGXrGEYT2sPemdS%2F-M5-0Rgnjb23s9oFr3lT%2F-M5-0b2PLckCNEkhGATr%2FRelation.JPG?generation=1586990838847083\&alt=media)

## More about attributes

* The set of allowed values for an attribute is called the **domain** of the attribute
* Attribute values are **atomic** i.e. indivisible (they can't be divided into sub-domains)
* The special value **null** is a member of every domain; it means that the value is not available or is unknown
* This null value may cause complications in the definition of many operations
* Aggregate functions ignore null values

## Relational Schema and Instance

A **relational schema** consists of a set of attributes and their domains.

$$R = (A\_1, A\_2, ..., A\_n)$$ where $$A\_1, A\_2, ..., A\_n$$ are attributes of the relation.

An **relation instance** refers to the tuples of a relation at a particular point in time. It is denoted as a table.

Note that relations are unordered i.e. the order in which the tuples are present in the table is irrelevant.

## Database

A database consists of multiple relations.

For example, a university database can have relations including student, instructor, advisor, department etc.

It is good to have separate relations instead of combining all the attributes into a single table. If we use a single table to represent everything, there would be two main issues:

* **redundancy**: ex. more than one student having the same instructor
* **null values**: ex. a student who doesn't have an advisor

The following figure illustrates the university database:

![](https://1736932896-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5-0RGXrGEYT2sPemdS%2F-M5-0Rgnjb23s9oFr3lT%2F-M5-0b2Tgtf246G-zkIr%2FUniversity%20Database.JPG?generation=1586990838857003\&alt=media)

Best practices to design "good" relational schemas will be discussed under normalization theory.
