Relational databases are databases based on relational models. In a relational database, a **relation** is table with columns and rows (not a relationship). An **attribute** is a named column in a relation, representing a characteristic of the entity. The **domain** is the set of allowable values for one or more attributes. A row is also called a **tuple**. Every tuple in a relation is distinct.
The process of defining the data model for a relational database is called [[database normalization]].
## degree
The degree of a relationships is the number of entities that participate in the relationship. Relationships of degree one are called **unary** (sometimes recursive) relationships. Relationships of degree two are called **binary** relationships. Most relationships in databases are binary. Relationships of degree three or more cannot be represented directly in a DBMS and must be converted to degree two relationships.
Each relationship can be defined by the combination of cardinality and participation. Options include
- (1, 1) required single relationship
- (0, 1) optional single relationship
- (1, N) required multiple relationship
- (0, N) optional multiple relationship
## cardinality
Cardinality refers to the number of instances of the entity involved in the relationship. The three types include one to many (1:N), many to one (N:1) and many to many (N:M). This is also called maximum cardinality as it represents the most entities that will participate in a relationship.
## participation
Participation (also called optionality) can be mandatory or optional. It is also called minimum cardinality as optional participation implies cardinality can be 0.
## superkey
A superkey is an attribute or set of attributes that uniquely identifies an instance. A candidate key is a minimal superkey. The primary key is the chosen candidate key. When there are multiple candidate keys, alternate keys are the candidate keys not chosen.
## foreign key
A foreign key represents the relation in another table. When relation A has a 1:N relationship with relation B, the foreign key will be placed in relation B. When the two relations are 1:1, the foreign key can be in either table (unless you decide to merge the two relations into one relation). When the relations are N:M, a **many-to-many table** (also called **intersection**) must be set up dedicated to store the relationships. For unary 1:M, the foreign key can be stored in the same relation. For unary N:M relations, a many-to-many table must be set up.
The relational database schema defines the relations and their attributes (where each relation has a relation schema). The general format is
- Name (Primary Key, Attribute, Foreign Key(fk)...)
The attribute(s) of the primary key should be underlined. Any foreign key should be noted with (fk).
---
Tables
[[Schema]]
Views
Indexes
Sequences
Data types
- [[Postgres data types]]
- [[primary key]]
- [[constraints]]
- [[enumerators]]
- [[relationships]]
- index