Designing relational databases

Problem

DB example

Problem

  • Как разработать структуру для БД?

Solution

  • Практиковаться

Intro

Steps

  • Выделение сущностей и их атрибутов

  • Атомизация сложных атрибутов на более простые.

  • Определение уникальных идентификаторов (первичных ключей)

  • Определение отношений между таблицами с помощью внешних ключей

  • Нормализация базы данных

Выделение сущностей и их атрибутов

  • восходящий

  • нисходящий

  • комбинированный

Keys

Primary Key

Attributes for Primary Key

  • Primary key value must be unique

  • Primary key cannot be NULL

  • Primary key values cannot be changed

  • The original key must be assigned a value when inserting a new entry

Composite Primary Key

Composite Key

Foreign Key

Attributes for Foreign Key

  • A foreign key may have a different name from its primary key

  • It ensures that rows in one table have corresponding rows in another

  • Unlike the primary key, they do not have to be unique. Most often they are not

  • Foreign keys may be null, although primary keys cannot

Relationship

Типы связей

  • One to one (Один к одному)

  • One to many (Один к многим)

  • Many to many (Многие ко многим)

One to one

One to one

One to many

One to many

Many to many

Many to many

Normalization

Normal Forms

Database normalization is the process of restructuring a relation database

Normal Forms

Normalisation Steps

Normalisation Steps

UNF

UNF

1NF

Rules for 1NF

  • It should only have single(atomic) valued attributes/columns

  • Values stored in a column should be of the same domain

  • All the columns in a table should have unique names

  • And the order in which data did store, does not matter

Example

1NF

2NF

Rules for 2NF

  • It should be in the First Normal form

  • It should not have Partial Dependency

Example

2NF
2NF

Example

2NF

Example

Foreign Key

Transitive Functional Dependencies

Example

Transitive Functional Dependencies

3NF

Rules for 3 NF

  • It is in the Second Normal form

  • It doesn’t have Transitive Dependency

Example

3NF
3NF
3NF