Relational Database Design (RDD) is the process of organizing data into structured tables that relate to one another. This process ensures that data is stored efficiently, avoids redundancy, and enables seamless queries and updates. In this lesson, you’ll learn the key stages of RDD and how to design databases with one-to-many relationships while applying normalization rules.
RDD can be broken into four stages:
The first stage is to identify the purpose of the database:
Next, identify the main entities (tables) needed for the database and their attributes (columns). For example, an e-commerce application might require:
products table: Contains product IDs, names, and prices.orders table: Stores order details and links to products and customers.users table: Stores customer information like IDs and names.Each table must have a primary key (PK)—a unique identifier for each record. In our e-commerce example:
products: Primary key is product_id.orders: Primary key is order_id.users: Primary key is user_id.Primary keys ensure each record is uniquely identifiable, making relationships between tables possible.
Relationships define how tables are connected. There are three types:
In a one-to-many relationship, one record in Table A is associated with multiple records in Table B. This is achieved using a foreign key (FK) in Table B that references the primary key in Table A.
Consider the following example:
users table:id name
1 Alice
2 Bob
orders table:id purchaser_id
10 1
11 1
12 2
Here, purchaser_id in the orders table is a foreign key referencing the id in the users table. This relationship indicates:
Normalization is the process of optimizing the database structure to minimize redundancy and ensure data integrity. The most commonly used normalization rules are:
These rules reduce redundancy, improve data consistency, and make the database easier to maintain.
Here’s how to create tables with a one-to-many relationship in SQLite3:
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
purchaser_id INTEGER,
FOREIGN KEY (purchaser_id) REFERENCES users(id)
);
This schema ensures each order is linked to a specific user while maintaining data integrity.
In this lesson, you explored the stages of Relational Database Design:
Relational database design is critical in many systems, including:
By following the RDD process and applying normalization rules, you can design efficient and reliable databases for a variety of applications.