Database Design for Health and Fitness Tracking Applications
Database Design for Health and Fitness Tracking Applications
Course Work
BAKI - 2024
1
Contents
Chapter 1. Health and Fitness Database
1.1 Introduction…………………………………………………………………3
1.2 ER diagram…………………………………………………………………4
Conclusion...........................................................................................................29
2
1. Health and Fitness Database
1.1 Introduction
The existing approach to health and fitness tracking relies heavily on manual
methods, such as handwritten logs or scattered digital tools, which can be time-
consuming and prone to errors. As the number of users tracking their fitness goals
increases, the complexity of managing this data grows significantly. Recording activities,
analyzing progress, and integrating health metrics from various sources into a cohesive
system become challenging without a centralized solution. This lack of efficiency can
lead to missed insights and hinder individuals from achieving their health objectives
effectively.
The purpose of the Database Design for Health and Fitness Tracking Applications is
to create a robust and secure system for storing and managing user data, including
personal fitness goals, workout logs, dietary information, progress reports, and wearable
device integrations. By centralizing and automating these processes, the system ensures
accuracy, efficiency, and a seamless experience for users striving for better health
outcomes.
1.2 ER diagram
The ER (Entity Relationship) diagram represents the model of the Health and Fitness
Tracking Application. This diagram illustrates the visual structure of the database tables
and their relationships, including members, trainers, branches, workout plans, and
payment systems. It serves as a tool for organizing structured data and defining
relationships between various functional components of the application. Key features of
the Health and Fitness Tracking Application Database Design include managing
members' profiles, workout plans, equipment, trainers, branches, payments, and
membership details.
3
4
2. Creating tables in the health and fitness database
Tables form the foundation of any database, serving as containers for structured data.
In the context of a health and fitness database, creating tables involves defining table
names, specifying columns, and determining appropriate data types for each column.
The SQL CREATE TABLE statement facilitates the creation of these tables, while the
INSERT INTO statement allows the addition of data rows, enabling the storage and
management of key information related to health and fitness activities.
1) Members
5
('Leman', 'Quliyeva', 'Woman', '1998.08.09',
'[email protected]', 'Ectomorph', 60, 175),
('Lale', 'Memmedova', 'Woman', '2001.02.03',
'lalememmedova2', 'Endomorph', 78, 168),
('Eli', 'Necefov', 'Man', '2002.01.04',
'[email protected]', 'Ectomorph', 70, 180),
('Aysel', 'Aliyeva', 'Woman', '1990.07.12',
'[email protected]', 'Mesomorph', 55, 162),
('Orkhan', 'Mammadov', 'Man', '1988.11.20',
'[email protected]', 'Endomorph', 85, 172),
('Leyla', 'Huseynova', 'Woman', '1995.03.14',
'[email protected]', 'Ectomorph', 60, 165),
('Farid', 'Guliyev', 'Man', '1992.05.25',
'[email protected]', 'Mesomorph', 88, 178),
('Nigar', 'Aliyeva', 'Woman', '1999.01.18',
'[email protected]', 'Endomorph', 75, 170);
select * from members
2) Membership
6
membership_name – This is the name of the membership
date_of_start – This is the starting date of a membership
date_of_finish – This is the last date of a membership
membership_price – This is the price of a membership
member_id – This is the ID of a member who bought a membership, it references
to the ID column of the members table.
3) Workout Plan
7
4) Trainers
8
5) trainer_member – This is the table for creating many-to-many relationship between
trainers and members tables.
9
6) Payments
7) Payment details
10
FOREIGN KEY (payment_id) REFERENCES payments (payment_id) ON
DELETE CASCADE ON UPDATE CASCADE
);
8) Equipments
12
10) branch_equipments – This is the table for creating many-to-many relationship
between branches and equipments tables.
13
11) branch_trainers – This is the table for creating many-to-many relationship between
branches and trainers tables.
12) Workers
14
worker_sex VARCHAR (10) NOT NULL,
worker_position VARCHAR (50) NOT NULL,
worker_birth DATE,
worker_email VARCHAR (100) UNIQUE,
worker_salary DECIMAL NOT NULL,
branch_id INT,
FOREIGN KEY (branch_id) REFERENCES branches (branch_id) ON DELETE
CASCADE ON UPDATE CASCADE
);
15
department_email VARCHAR (100) UNIQUE NOT NULL,
branch_id INT,
FOREIGN KEY (branch_id) REFERENCES branches (branch_id) ON DELETE
CASCADE ON UPDATE CASCADE
);
DROP COLUMN is used to drop column in a table. Deleting the unwanted columns
from the table.
16
2.3 SQL constraints
SQL constraints are used to specify rules for the data in a table. Constraints are
used to limit the type of data that can go into a table.
There is a PRIMARY KEY in the ID column of the members, which means We can
not add same data to this column.
There is UNIQUE constrant in the member_email column. This means that all the
values in the column are different.
With the following statement we add NOT NULL constraint to the member_birth
column of the members table.
17
3. SQL queries. Using SQL to Retrieve Information from tables
3.1 SQL select, order by, where command, update, delete statements
1. This query lists the branches that their ratings are below 5. Here we used ASC. The
ASC command is used to sort the data returned in ascending order.
2. This query lists the workers whose position is cleaner, depending on their birth date.
18
3. The UPDATE statement is used to modify the existing records in a table. Here, we’ll
update the weight of a member.
update members
set member_weight = 95 where member_name = 'Vusal';
4. The DELETE statement is used to delete existing records in a table. Here, we’ll delete
member Eli from our table.
19
delete from members where member_id = 5
1. The IN operator allows you to specify multiple values in a WHERE clause. The IN
operator is a shorthand for multiple OR conditions. The following query is to find all
members whose body types are either "Ectomorph" or "Endomorph".
SELECT
member_name,
member_surname,
body_type
FROM
members
WHERE
body_type IN ('Ectomorph', 'Endomorph');
2. The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates. The following query is to retrieve memberships with prices
between 50 and 200.
20
SELECT
membership_name,
membership_price
FROM
membership
WHERE
membership_price BETWEEN 50 AND 200;
3. The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column. The following query is to find members whose surname starts with the letter "S".
SELECT
member_name,
member_surname
FROM
members
WHERE
member_surname LIKE 'E%';
4. The following query is to retrieve members who weigh more than 70 kg and are either
"Male" or "Female" with a height greater than 170 cm.
SELECT
member_name,
member_surname,
member_weight,
member_height,
member_sex
FROM
21
members
WHERE
member_weight > 70
AND member_height > 170
AND (member_sex = 'Man' OR member_sex = 'Woman');
SELECT TOP 5
worker_name,
worker_surname,
worker_salary
FROM
workers
ORDER BY
worker_salary DESC;
1. This query calculates the total sum of all payments made by all members. Here, we’ll
use SUM() aggregate function.
SELECT
SUM(amount_of_payment) AS total_payments
FROM
payments;
22
2. This query finds the count of members for each membership type. Here, we’ll use
COUNT() aggregate function.
SELECT
ms.membership_name,
COUNT(ms.member_id) AS member_count
FROM
membership ms
GROUP BY
ms.membership_name;
3. This query retrieves the minimum and maximum prices of memberships. Here, we’ll
use MIN() and MAX() aggregate functions.
SELECT
MIN(membership_price) AS minimum_membership_price,
MAX(membership_price) AS maximum_membership_price
FROM
membership;
23
4. This query calculates the average weight of members who are male. Here, we’ll use
AVG() aggregate function.
SELECT
AVG(member_weight) AS average_male_weight
FROM
members
WHERE
member_sex = 'Man';
1. The INNER JOIN keyword selects records that have matching values in both tables.
The following query is to fetch member names along with their trainer names using an
inner join.
24
2. The RIGHT JOIN keyword returns all records from the right table, and the matching
records from the left table. The following query is to list all branches and the equipment
assigned to each branch. This ensures that all branches are included, even if no
equipment has been assigned to them.
3. The LEFT JOIN keyword returns all records from the left table , and the matching
records from the right table . The result is 0 records from the right side, if there is no
match. The following query is to list all trainers and their assigned branch details.
25
4. The following query is to list each membership program's name and the total payments
made for that program.
1. The following query is to find the Membership Program with the Maximum Price.
3. The following query is to list branch details where at least one worker earns above the
average worker salary.
27
3.4 SQL views
1. A view is a virtual table based on the result-set of an SQL statement. The following
query is to combine the members and membership tables to display each member’s
name, their membership program, and the price.
2. This view joins the payments and members tables to show payment details for each
member, including their name, payment amount, and payment method.
Conclusion
In today’s data-driven world, efficient database systems are essential for managing
and organizing information. The Health and Fitness Tracking Application database
simplifies the process of storing and retrieving member data, membership details, trainer
schedules, payments, and equipment inventory. Traditionally, fitness centers relied on
manual processes to manage their operations, which were time-consuming and prone to
errors.
With the implementation of this database system, tasks such as assigning trainers to
members, tracking membership payments, and managing gym equipment are
streamlined and automated. This ensures accuracy, reduces manual workload, and
enhances the overall experience for both staff and members. The system also supports
easy scalability, making it adaptable for fitness centers of all sizes. By adopting such a
system, fitness centers can focus more on delivering quality services while ensuring
efficient and reliable data management.
29
30