wiki

Help! I'm trapped in a wiki!

Site Tools


computer:databases

Databases

Databases are ways to store data in an organized way.

I am learning about relational databases on Oracle Academy.

ERD

An Entity Relationship Diagram is a logical model of how your database is going to work.
It contains entities and relationships!

You should check an ERD against the CRUD model.

CRUD

Create, Read, Update, Delete operations form the basis of using a database.

If your ERD contains entities that cannot have CRUD applied to them, you should rethink your ERD.

Unique identifiers

UIDs are used to uniquely identify an instance of an entity.
An example would be Social Security Numbers (SSN), CNP, Student ID…

They can be simple or composite (multiple attributes make up one UID), and artificial (The SSN is something we make up, not a real life feature)

An entity has a single primary UID, and can have more secondary UIDs.

UIDs will become primary keys in the database.

Normalization

Normalization means to ensure data is stored in one single place within the database.

For example, it would be pretty hard to store phone numbers in three different places (phone, address book and a sticky note).
Data should be created, stored, updated and deleted in one place only.

First normal form

1NF requires that no entities have multi-valued attributes.
In essence, this means that an entity with multiple values for an attribute should have that attribute separated into an entity of its own.
The new entity is related with a 1:M relationship to the original entity.

Example: If a SCHOOL BUILDING entity has a CLASSROOM attribute, it's clear that more classrooms can be housed in a single building, so 1NF is broken.
To fix this, separate CLASSROOM into its own entity (complete with UID and required attributes) and relate it to SCHOOL BUILDING with 1:M.

Second normal form

2NF requires that no entities have attributes that don't depend on the UID.
In essence, this means an entity should have only relevant attributes.

Example: PRODUCT entity has Name and ID attribute; ORDER LINE entity has Price and ID attribute. It's clear that PRODUCT should have the Price attribute, not ORDER LINE (Price is only relevant for the product, not the order line)
To fix this, move the Price attribute from ORDER LINE to PRODUCT.

Third normal form

3NF requires that no regular attributes should be dependent on another regular attribute.
In essence, this means you should model entities that do not depend on information not related to it.
Entites should have attributes related only to it!

Example: a CD entity has these attributes: ID, Name, Year, Store name, Store address. It's clear that the Store attributes do not belong in the CD entity (what if the store's name is changed?)
To fix this, separate the attributes into an entity of its own.

computer/databases.txt · Last modified: by 127.0.0.1