0% found this document useful (0 votes)
8 views14 pages

Databases I - 02 Logical Modeling, Docker

The document provides an overview of the relational data model, including its logical design, benefits, and disadvantages. It details the building blocks of the model such as relations, attributes, and keys, and outlines the process of converting an E-R model to a relational data model. Additionally, it discusses the use of Docker for setting up MySQL and phpMyAdmin, including configuration details for container management.

Uploaded by

kgztjmqsss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Databases I - 02 Logical Modeling, Docker

The document provides an overview of the relational data model, including its logical design, benefits, and disadvantages. It details the building blocks of the model such as relations, attributes, and keys, and outlines the process of converting an E-R model to a relational data model. Additionally, it discusses the use of Docker for setting up MySQL and phpMyAdmin, including configuration details for container management.

Uploaded by

kgztjmqsss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

27/03/2025

Relational data
model

Logical DB design

• Logical modelling is the process of designing a logical model for


information use in a complete organised system, based on the selected
data model of the target DBMS. During the logical model design phase,
the model is also tested against user requirements. In doing so, we use a
normalisation process to check the correctness of the logical model.

97

1
27/03/2025

Relational data model


• It is based on a mathematical structure - relational theory and first-order
predicate calculus.
• Obtained by conversion from E-R model.

 Benefits:  Disadvantages:
 simplicity,  software products that work in
 no knowledge of the physical structure is conjunction with a relational data model
required, can be slow.
 access to data is unlimited, depending on
the number of different accesses,
 access to data is easy,
 Multi-level data integrity is built in.

98

Relational data model -


building blocks
• Relation:
• It is a two-dimensional table with columns and rows.
• Relation (mathematical concept).
• Table (physical concept).
• Attribute:
• represents the name of the relation column or relation property.
• Domain:

99
• is the set of admissible values for one or more attributes.
• N tuple:
• is a relation line representing a single record or providing data for a single
object (entity) of a closed organised world.

2
27/03/2025

Relational data model -


building blocks
• Relation rate:
• is represented by the number of attributes of the relation
• The cardinality of the relationship:
• is represented by the number of rows contained in the relation.
• Relational scheme:
• is the name of the relation followed by a set of attributes: R (A1, A2,
...., An)
• It is the name of a relation followed by a set of pairs consisting of
attributes and domains: A1, A2, ...., An should be attributes with
domains D1, D2, ...., Dn. Then the set {A1:D1, A2:D2,..., An:Dn} is the
relational schema of the relation R.
100

Relational data model / E-R model


Entity-relationship Relational model - Relational model -
model formal informal
E-R diagram Relational scheme Description of tables
Entity Directions Table
Instance of an entity N-terica Line
Attribute Attribute Column
Candidate key, primary
Key Candidate key, primary key
key
Include the primary key of the other session as a
Cardinality ratio 1:1
foreign key or combine the two into one session
Include the primary key from page "1" as a foreign key
Cardinality ratio 1:N
in page "N"

101

3
27/03/2025

Creating a relational data model


attributes
Student
ID name enrolment_nr date_of_birth email fk_faculty relational
scheme - header
1 David E9320376041 12.12.2001 [email protected] 1
relation line /
2 May E3107410974 15.3.2001 [email protected] 2
/ table n-terica
3 Ales E1234464687 NULL Aleš@feri.si 1

cell column
primary key foreign key
Faculty
name of the
ID name Description
table
1 FERI FERI is a renowned educational Cardinality
and research institution...
2 EPF The ETF offers a wide range of
study programmes at bachelor,
master and doctoral level.

102
degree of relation

Relational data model - building blocks Compiled by


External (foreign)

Candidate Secondary
Primary
• Key:
• is an attribute or set of attributes that uniquely
specify a row within the table. Student
• primary ID enrolment_nr date_of_birth email fk_Faculty
• is that attribute or group of attributes 1 E9320376041 12.12.2001 [email protected] 1
within a table that will uniquely
2 E3107410974 15.3.2001 [email protected] 2
specify each row in the table.
• candidate
• is a key of which no real subset is a superset of the table key.
• composite / composite
• is a key consisting of more than one attribute.
• Secondary
• is a candidate key that has not been selected as the primary key. Faculty
• tuj (external) / foreign ID name Number_of_students
• is an attribute or group of attributes within a table that is the primary key
of another table (the source table). 1 FERI 3000
2 EPF 2000

103

4
27/03/2025

Creating a relational data model


• A domain is a set of admissible values for one or more attributes.

Attribute Domain name Domain definition


parent_number EMŠO Number; length: 24
company_name Title character string; length: 30
first_last_name Title character string; length: 30

sex Gender character; length: 1; possible values: M or Z

104

Creating a relational data


model
• Table names are unique. No two tables in the database
have the same name.
• Each attribute within the table has a unique name.
• The values of each attribute have the same domain.
• The order of the attributes (columns) in the table is irrelevant.

105
• The order of the rows in the table is irrelevant.
• Each table must have a primary key.

5
27/03/2025

Creating a relational data model -


integrity

• Entity integrity
• In a table, the primary key cannot have the value null.

• Referential integrity/integrity
• If there is a foreign (foreign) key in the relation, its value must
be identical to the value in its source table, or it must be null.
• The foreign key must not contain values that are not present
in the primary table.

106

Conversion from E-R model to relational data model


1.
Each entity E from the E-R model is translated into a table R.

E (A1, A2, ..., An)  R (A1, A2, ..., An) Worker (ID, name, surname, date of
birth)

107

6
27/03/2025

Conversion from E-R model to relational data model


2.
For each 1:1 cardinality table, we define the
corresponding relations (tables) S and T that
belong to the entities that the table connects.
Add a foreign key (the primary key of the other
table) to one of the tables. Add any table
attributes to the table with the foreign key.
E1 (E11, E12, ..., E1n)  S (S1, S2, ..., Sn) Worker leads the department (1:1)
E2 (E21, E22, ..., E2m)  T (T1, T2, ..., Tm)
Worker (ID, first name, surname, date
of birth)
Re (A1, A2, ..., An) W
Department (ID, department_name,
S (S1, S2, ..., Sn, T1, A1, A2, ..., An ) department_description,
or fk_WORKER)
T (T1, T2, ..., Tm, S1, A1, A2, ..., An )
108

Conversion from E-R model to relational data model


3.
For each cardinality table 1:N, define the
corresponding tables S and T, translating the
entity on cardinality side 1 into table S and the
entity on side N into table T. Add the primary key
of table S and any attributes of the table linking
entities E1 and E2 into table T.
E1 (E11, E12, ..., E1j) S (S1, S2, ..., Sn) Department employs workers (1:N)
E2 (En1, En2, ..., Enn) T (T1, T2, ..., Tn)
Worker (ID, first name, surname, date
of birth, fk_department)
Re (A1, A2, ..., An) W
Department (ID, department_name,
T (T1, T2, ..., Tn, S1, A1, A2, ..., Aj ) and department_description)
S (S1, S2, ..., Sn)
109

7
27/03/2025

Conversion from E-R model to


relational data model
STEP 4 (we have already done this in the E-R
model design, so we only have 1:N relations).
For each relation of cardinality M:N, we define
the corresponding relations (tables) S and T, and
for the relation, we introduce a new relation
(table) to which we transfer the primary keys of
tables S and T as foreign keys, and add any
attributes of the table connecting the entities En
and Em.
En (En1, En2, ..., Enm)  S (S1, S2, ..., Sm) Workers participate in projects (M:N)
Em (Em1, Em2, ..., Emk)  T (T1, T2, ..., fk) Project (ID, project_name, project_start,
projected_completion)
Worker (ID, first name, surname, date of birth,
Re (A1, A2, ..., An)  R (S1, T1, A1, A2, ..., An )
fk_department)
Participation (ID, fk_worker, fk_project,
no_hours)
110

Relational DBMS
• A relational database is a type of database.
• It uses a structure that allows us to identify and access
data in relation to other pieces of data in the database.
Often the data in a relational database is organised into
tables.
• Relational DBMS is a program where you can create,
update, administer a relational database. Most
relational DBMSs use SQL to access the database.

111

8
27/03/2025

Graphical
interfaces for
working with the
MySQL
database

113

9
27/03/2025

Graphical interfaces for working with databases


• MySQL Shell  phpMyAdmin

114

Graphical interfaces for working with databases


• Oracle SQL developer  HeidiSQL

115

10
27/03/2025

Docker - for
setting up
phpMyAdmin
& MySQL

Docker
• Installing Docker Desktop from https://www.docker.com/
• A new Docker folder somewhere on the disk (e.g. D:\Docker)
• Inside the folder, a new docker-compose.yml file
• YAML = human readable data serialisation language (used
for configuration files and in applications where data is
stored or transmitted)
• From the Docker Hub https://hub.docker.com/, find the tools
you need (e.g. php:apache, mysql, phpMyAdmin)

11
27/03/2025

Images and containers

Docker hub - mysql


• Under tags we look for what we
mysql:
container_name: mysql-pb # Container name, you can change
it if you want, but it must be unique within the Docker
need, here is for example environment
image: mysql:8.0.41 # Docker image downloaded from

mysql version 8.0.41 https://hub.docker.com/_/mysql. You can use the version as in


this example (8.0.41), or use 'latest' for the latest version
restart: unless-stopped # Allows the container to be
restarted in case of an error, unless manually stopped by the
user
environment:
- MYSQL_ROOT_PASSWORD=superVarnoGeslo # Set the password
for the root user. It is recommended that this password is
secure and unique
volumes:
- ./data/mysql:/var/lib/mysql # Associates the local
folder './data/mysql' with the MySQL data folder inside the
container to preserve data during restarts
port:
- "3306:3306" # Connects the internal port 3306 (default
MySQL) to the external port 3306, allowing access to MySQL
outside the container (the port on the left side of the binary
can be changed as desired)

12
27/03/2025

Docker hub - phpmyadmin


• Under tags we look for what we phpmyadmin:
need, for example here is container_name: phpmyadmin-pb # Container name for
phpMyAdmin. You can change it as you wish, but it must
phpmyadmin:latest be unique within the Docker environment
image: phpmyadmin/phpmyadmin:latest # Docker image
for phpMyAdmin. 'latest' will download the latest
version
restart: unless-stopped # Allows the container to
restart in case of an error, unless manually stopped
by the user
port:
- "8000:80" # Binds internal port 80 to external
port 8000, allowing access to phpMyAdmin via a browser
at http://localhost:8000 (the port on the left side of
the colon can be changed at will)
environment:
PMA_HOST: mysql-pb # Name of the MySQL container
to which phpMyAdmin connects. This is the name of the
MySQL container ('mysql-pb') used by Docker for
networking between containers.

docker-compose.yml
services:
mysql:
container_name: mysql-pb # Container name, you can change it if you want, but it must be unique within the Docker environment
image: mysql:8.0.41 # Docker image downloaded from https://hub.docker.com/_/mysql. You can use the version as in this example
(8.0.41), or use 'latest' for the latest version
restart: unless-stopped # Allows the container to be restarted in case of an error, unless manually stopped by the user
environment:
- MYSQL_ROOT_PASSWORD=superVarnoGeslo # Set the password for the root user. It is recommended that this password is secure
and unique
volumes:
- ./data/mysql:/var/lib/mysql # Associates the local folder './data/mysql' with the MySQL data folder inside the container
to preserve data during restarts
port:
- "3306:3306" # Connects the internal port 3306 (default MySQL) to the external port 3306, allowing access to MySQL outside
the container (the port on the left side of the binary can be changed as desired)

phpmyadmin:
container_name: phpmyadmin-pb # Container name for phpMyAdmin. You can change it as you wish, but it must be unique within the
Docker environment
image: phpmyadmin/phpmyadmin:latest # Docker image for phpMyAdmin. 'latest' will download the latest version
restart: unless-stopped # Allows the container to be restarted in case of an error, unless manually stopped by the user
port:
- "8000:80" # Binds internal port 80 to external port 8000, allowing access to phpMyAdmin via a browser at
http://localhost:8000 (the port on the left side of the colon can be changed at will)
environment:
PMA_HOST: mysql-pb # Name of the MySQL container to which phpMyAdmin connects. This is the name of the MySQL container
('mysql-pb') used by Docker for networking between containers.

13
27/03/2025

A few more commands

• What's on the right side of the dock is always tied to the docker itself, and what's on the left side is tied to the local computer.
• A few commands
• # start (includes image downloads)
• docker compose up
• # off
• docker compose down
• #if we are just transmitting an image
• docker compose pull
• #if only updating
• docker compose up -d
• #when we download and run
• docker-compose pull && docker-compose up -d

Start
• Start the terminal in the folder where you have Docker and
docker-compose.yml file.
• Enter docker compose up for first boot and image download

14

You might also like