A3.1 Database Fundamentals

A3.1.1 Explain the features, benefits and limitations of a relational database.

Flat File vs Relational

  • Database: a systematically stored collection of data.
  • Flat file: all data in one table. Data repeats, wastes storage, becomes inconsistent, hard to scale.
  • Relational: data split into several linked tables. Each fact stored once.
  • Normalization: organising data to minimise the risk of anomalies.

Anomalies

An anomaly is an issue caused by incorrect handling of data in a database.

AnomalyProblemExample (vet flat file)
InsertCan't add data without unrelated data.A new vet can't be added until they treat a patient.
DeleteDeleting one thing removes data you need.Deleting a vet also deletes the pet and owner in that row.
UpdateChange missed in some rows, data becomes inconsistent.Vet moves house, only some rows updated, two addresses exist.

Features

TermMeaningExample
EntityA table.OWNER, PET
AttributeA characteristic of the data (column).Pet_Name
Primary keyUnique value for each row.Pet_ID
Foreign keyA primary key placed in another table to create a relationship.Owner_ID inside PET
Composite keyTwo or more whole attributes together form a unique key.Patient_ID + Date
Concatenated keyParts of attributes joined into one unique value.First letters of name + surname + date of birth
RelationshipThe link between two entities.OWNER owns PET
OWNER: Owner_ID (PK)Name
393939Andrea
5893021Amalia
PET: Pet_ID (PK)NameOwner_ID (FK)
H849Paolo393939
C192Felix393939
C059Bao5893021

Cardinality and Modality

Cardinality (how many):
  • 1:1 one person, one passport.
  • 1:N one vet, many treatments.
  • M:N many students, many courses.
Modality (must it exist):
  • Optional: actor and TV show. Some actors only do stage.
  • Mandatory: receipt and item. A receipt needs at least one item.

Benefits and Limitations

BenefitsLimitations
Reduced duplication and redundancyPoor for big data scalability
Data consistencyDesign complexity
Data integrityRigid schema
Easy retrieval with SQLInefficient for deep hierarchical data
Concurrency control (ACID)Struggles with unstructured data
Reliable transaction processingObject relational impedance mismatch (tables don't map neatly onto OOP objects)
Built in multiuser security
Scales better than flat file
Community support
Ninja Notes: