Database Exercises
Exercise3 Planning Databases

In these exercises, you will study how to plan and build databases based on given requirements.

Database Design Principles

When designing a relational database, follow these key steps to ensure a well-structured and efficient database:

1. Identify Tables and Relationships

Start by identifying the main entities (tables) in your system. For each entity, determine:

  • What data needs to be stored - Identify the attributes (columns) for each table
  • Primary keys - Every table must have a unique identifier (primary key)
  • Relationships between tables - Determine how tables are connected to each other
2. Check Relationship Types

Examine all relationships between tables and verify their cardinality:

  • One-to-One (1:1) - One record in Table A relates to one record in Table B
  • One-to-Many (1:n) - One record in Table A relates to many records in Table B
  • Many-to-Many (n:m) - This is NOT allowed in relational databases!

Important: If you find a many-to-many relationship, you must resolve it by creating a junction table (also called bridge table or linking table). This junction table will have foreign keys pointing to both related tables, converting the many-to-many relationship into two one-to-many relationships.

3. Normalization

Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. This includes creating tables and establishing relationships between those tables according to rules designed to protect the data and make the database more flexible.

The main goals of normalization are:

  • Eliminate redundant data - Store each piece of information only once
  • Ensure data dependencies make sense - Data should be logically organized
  • Make the database easier to maintain - Changes should be easy to implement

The most common normalization levels are:

  • First Normal Form (1NF) - No repeating groups or multi-valued fields
  • Second Normal Form (2NF) - All non-key attributes depend on the whole primary key
  • Third Normal Form (3NF) - All non-key attributes depend only on the primary key

For most applications, achieving Third Normal Form (3NF) is sufficient and recommended.



Toggle Menu