0% found this document useful (0 votes)
24 views

ICTMC Fundamentals of Database

Uploaded by

alamat888
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

ICTMC Fundamentals of Database

Uploaded by

alamat888
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 123

FUNDAMENTALS

OF DATABASE
ADMINISTRATION
2

FAQ
What is it?
Why do we need it?
How does it work?
This lecture is designed to provide an initial and
fundamental knowledge in Database Administration
concepts, advantages of database automation, types
of database , data types and attributes,
Normalization Concept this will also introduce
MYSQL Database, Data Manipulation Language,
Data Definition Language and Database Constraints.
Fundamentals of Database Administration with MYSQL 4

LEARNING OUTCOMES

• To Learn and Discover Concepts of Database


• To Learn and Discover different Database
terminologies.
• To perform and create Database using MySQL
Fundamentals of Database Administration with MYSQL 5

PART I

DATABASE
MANAGEMENT
SYSTEM CONCEPT
Fundamentals of Database Administration with MYSQL 6
Fundamentals of Database Administration with MYSQL 7
Fundamentals of Database Administration with MYSQL 8

• Unorganized
• Unstructured
• Inefficient

• Chaotic
Fundamentals of Database Administration with MYSQL 9
Fundamentals of Database Administration with MYSQL 10
Fundamentals of Database Administration with MYSQL 11

• Organized
• Structured
• Efficient

• Neat
Fundamentals of Database Administration with MYSQL 12

WHAT IS DATABASE
A database is an organized collection
of structured information, or data,
typically stored electronically in a
computer system. A database is
usually controlled by a database
management system (DBMS).
Fundamentals of Database Administration with MYSQL 13

DATABASE
• Different Category of files
• Different types of reports
Fundamentals of Database Administration with MYSQL 14

HISTORY
Computerized databases started in the
1960s by Charles W Bachman, when
the use of computers became a more
cost-effective option for private
organizations. The history of
computers and databases are
interlinked. As prices dropped it
became easier to shift data storage
and databases to computers.
Fundamentals of Database Administration with MYSQL 15

HISTORY
There were two popular data models in
this decade: a network model called
CODASYL and a hierarchical model
called IMS. One database system that
proved to be a commercial success
was the SABRE system that was used
by IBM to help American Airlines
manage its reservations data.
Fundamentals of Database Administration with MYSQL 16

SABRE SYSTEM
Fundamentals of Database Administration with MYSQL 17

4 TYPES OF DATABASE
MANAGEMENT SYSTEM

• Relational Database(RDBMS)
• Hierarchical Database Model
• Network Database Model
• Object Oriented Database
Fundamentals of Database Administration with MYSQL 18

HIERARCHICAL DATABASE MODEL

resembles a tree structure, similar to a folder


architecture in your computer system. The
relationships between records are pre-
defined in a one to one manner, between
'parent and child' nodes. They require the
user to pass a hierarchy in order to access
needed data. Due to limitations, such
databases may be confined to specific uses.
Fundamentals of Database Administration with MYSQL 19

Key Characteristics:
•Tree-like structure: Data is stored in a hierarchical
arrangement, with each record having a single parent and
multiple children.
•One-to-many relationships: A parent record can have
multiple child records, but a child record can only have one
parent.
•Limited flexibility: The hierarchical model is not well-
suited for complex relationships or large-scale data storage.
•Efficient for certain types of data: Hierarchical databases
are efficient for storing and retrieving data with a natural
hierarchical structure, such as file systems, organizational
charts, or network topology analysis.
Fundamentals of Database Administration with MYSQL 20

Advantages:
•Fast data retrieval: Hierarchical databases allow for efficient
retrieval of data, as the tree-like structure enables quick
navigation to specific records.
•Simple data relationships: The one-to-many relationships in a
hierarchical database make it easy to understand and manage
data relationships.
Disadvantages:
•Limited scalability: Hierarchical databases can become
cumbersome and inefficient as the data grows in size or
complexity.
•Limited flexibility: The rigid tree-like structure makes it
difficult to accommodate changes or additions to the data
model.
Fundamentals of Database Administration with MYSQL 21

Use Cases:
•File systems: Hierarchical databases are well-suited for storing
and managing file systems, where files are organized in a tree-
like structure.
•Organizational structures: Hierarchical databases can be used
to store and manage organizational charts, where employees
are arranged in a hierarchical structure.
•Network topology analysis: Hierarchical databases can be
used to analyze and store network topology data, where
devices are connected in a hierarchical structure.
Fundamentals of Database Administration with MYSQL 22

NETWORK DATABASE MODEL

also have a hierarchical structure. However,


instead of using a single-parent tree
hierarchy, this model supports many to many
relationships, as child tables can have more
than one parent.
Fundamentals of Database Administration with MYSQL 23

Key Features:
1.Graph Structure: The network model represents data as a
graph, where nodes (records) are connected by edges
(relationships).
2.Many-to-Many Relationships: Each record can have
multiple parent and child records, forming a generalized graph
structure.
3.Schema: The schema is viewed as a graph, where
relationship types are arcs and object types are nodes.
4.Flexible: The network model is more flexible than the
hierarchical model, allowing for complex relationships and
navigational access.
5.Complex Query Performance: Graph databases optimized
for network models can deliver fast query responses for
complex relationship-based queries.
Fundamentals of Database Administration with MYSQL 24

Advantages:
1.Efficient Query Performance: The network model excels in
handling relationships, making it suitable for applications that
require frequent traversals of relationships.
2.Scalability: While network data models can degrade in
performance with large datasets or complex graphs, scaling
strategies can be employed to maintain query performance.
Fundamentals of Database Administration with MYSQL 25

Disadvantages:
1.Complexity: The network model’s graph structure can be
complex to design and implement.
2.Data Integrity: Ensuring data integrity can be challenging
due to the flexibility of the model.
3.Lack of Standardization: The network model lacks a
standardized implementation, making it difficult to integrate
with other systems.
Fundamentals of Database Administration with MYSQL 26

Use Cases:
1.Telecommunications Networks: The network model is well-
suited for modeling complex relationships between network
nodes and edges.
2.Inventory Management: The model can efficiently handle
relationships between items, suppliers, and customers.
3.Social Networks: The network model represents individuals
as nodes, and connections between them (e.g., friendship,
family, professional relationships) as edges.
Fundamentals of Database Administration with MYSQL 27

OBJECT ORIENTED DATABASE

the information is represented as


objects, with different types of
relationships possible between two or
more objects. Such databases use an
object-oriented programming language
for development.
Fundamentals of Database Administration with MYSQL 28

Key Characteristics:
1.Objects: Data is stored as self-contained objects, each with
its own set of attributes (data) and methods (procedures).
2.Classes: Objects are instances of classes, which define the
structure and behavior of objects.
3.Inheritance: Classes can inherit properties and behavior
from parent classes, allowing for a hierarchical organization
of data.
4.Polymorphism: Objects of different classes can be treated
as if they were of the same class, enabling generic
operations.
5.Encapsulation: Objects hide their internal implementation
details and expose only necessary information to the outside
world.
Fundamentals of Database Administration with MYSQL 29

Advantages:
1.Improved data modeling: OOM allows for more accurate
representation of real-world entities and their relationships.
2.Increased flexibility: Objects can be easily modified or
extended without affecting other parts of the database.
3.Better support for complex domains: OOM is well-suited
for domains with complex relationships and behaviors.
Fundamentals of Database Administration with MYSQL 30

Challenges:
1.Steep learning curve: Developers need to understand OOP
concepts and how they apply to databases.
2.Performance: OOM can be slower than traditional
relational databases due to the overhead of object creation
and method invocation.
3.Scalability: OOM can be more challenging to scale
horizontally (add more machines) due to the complexity of
object relationships.
Fundamentals of Database Administration with MYSQL 31

Examples:
1.ObjectDB: A Java-based Object-Oriented Database
Management System (OODBMS) that provides transparent
persistence for Java objects.
2.Object-relational Data Model: A combination of Object-
Oriented and Relational database models, which supports
both object-oriented and relational data structures.
Fundamentals of Database Administration with MYSQL 32

RELATIONAL DATABASE MODEL

Contains multiple tables of data with


rows and columns that relate to each
other through special key fields.
Fundamentals of Database Administration with MYSQL 33

Key Concepts:
•Relations: Tables that store data, with each row representing
an entity and each column representing a property or
attribute.
•Tuples: Individual rows in a relation, containing values for
each attribute.
•Schema: The overall structure of the relations, including the
relationships between them.
•Primary keys: Unique identifiers for each tuple in a relation,
ensuring data integrity and enabling joins between relations.
•Foreign keys: References to primary keys in other relations,
establishing relationships between them.
Fundamentals of Database Administration with MYSQL 34

Relationships between Relations:


•Join: Combining tuples from multiple relations based on
matching values in their primary keys or foreign keys.
•Referential integrity: Ensuring that foreign key values in one
relation match the primary keys in another relation.

Benefits:
•Data normalization: Reducing data redundancy and
improving data integrity by storing each piece of data in one
place.
•Improved query performance: Allowing for efficient querying
and joining of data across multiple relations.
Fundamentals of Database Administration with MYSQL 35
Fundamentals of Database Administration with MYSQL 36

Dr. Edgar F. Codd published an important


paper that served as the introduction of the
relational database, and his ideas changed
the way people thought about databases. In
his model, the database’s schema, or logical
organization, is disconnected from physical
information storage, and this became the
standard principle for database systems.

Father of Relational Database


Fundamentals of Database Administration with MYSQL 37

2 TYPES OF DATABASE STRUCTURE

A flat file database stores data in a


plain text file, with each line of text
typically holding one record.
Delimiters such as commas or tabs
separate fields. A flat file database
uses a simple structure and, unlike a
relational database, cannot contain
multiple tables and relations.
Fundamentals of Database Administration with MYSQL 38

SleekDB is a simple flat file


NoSQL like database implemented
in PHP without any third-party
dependencies that store data in
plain JSON files.

MongoDB
Fundamentals of Database Administration with MYSQL 39

A relational database contains multiple


tables of data with rows and columns that
relate to each other through special key
fields. These databases are more flexible
than flat file structures, and provide
functionality for reading, creating, updating,
and deleting data.
Fundamentals of Database Administration with MYSQL 40

RELATIONAL DATABASE

Popular Relational Database:

MS SQL Server
MySQL
MariaDB
SQLite
PostgreSQL
Fundamentals of Database Administration with MYSQL 41

TYPES OF RELATIONSHIPS

• one to one
• one to many
• many to one
• many to many
Fundamentals of Database Administration with MYSQL 42

ERD – ENTITY RELATIONSHIP DIAGRAM


Fundamentals of Database Administration with MYSQL 43

ONE TO ONE

• where one table record relates to


another record in another table
Fundamentals of Database Administration with MYSQL 44

ONE TO MANY

• where one table record relates to


multiple records in another table
Fundamentals of Database Administration with MYSQL 45

MANY TO ONE

• where more than one table record


relates to another table record
Fundamentals of Database Administration with MYSQL 46

MANY TO MANY

• where multiple records relate to more than


one record in another table
Fundamentals of Database Administration with MYSQL 47
Fundamentals of Database Administration with MYSQL 48
Fundamentals of Database Administration with MYSQL 49

DATABASE TERMS

Fieldnames – Represent your columns


Records – Represent your rows
Datatypes – Restrict value of a field
Attributes – A data that describes entity
Fundamentals of Database Administration with MYSQL 50

Database

Table

Field Names, Datatype


and Constraints

Records
Fundamentals of Database Administration with MYSQL 51

RULES IN NAMING TABLE,DATABASE


And FIELDS

• Don’t use space, you may use


Underscore or hyphen.
• Case Sensitive
• Avoid using database reserved words
• Don’t start with a number.
• Don’t use special characters.
Fundamentals of Database Administration with MYSQL 52

DATATYPE

It is the restrict value of a field or simply the


type of data needed to be enter.

COMMON DATATYPES

Numeric Data types


String Data types
Date and time Data types
53

Database Administration
54

Database Administration
55

Database Administration
Fundamentals of Database Administration with MYSQL 56

CONSTRAINTS

a key feature of database management


systems. They ensure that rules defined at
data model creation are enforced when the
data is manipulated ( inserted, updated, or
deleted) in a database.
Fundamentals of Database Administration with MYSQL 57

CONSTRAINTS
Fundamentals of Database Administration with MYSQL 58

Relational databases use Structured Query


Language (SQL) - a standard user
application that provides an easy
programming interface for database
interaction.

Popular examples of standard relational


databases include Microsoft SQL Server,
Oracle Database, MySQL and IBM DB2.
Fundamentals of Database Administration with MYSQL 59
Fundamentals of Database Administration with MYSQL 60
Fundamentals of Database Administration with MYSQL 61
Fundamentals of Database Administration with MYSQL 62

PART 2

CHARACTERSET
AND COLLATION
Fundamentals of Database Administration with MYSQL 63

CHARACTERSET

Set of all characters included in that


Chracterset.

Ex: Characterset used in mysql is latin1

ABC etc..
123 etc..

It can’t use other languages like Japanese


and Chinese.
Fundamentals of Database Administration with MYSQL 64

COLLATION

Collation is a set of rules applied when


Comparing and sorting characters used by
The Database.

For old versions of mysql default characterset


Was latin1 default collation was
Latin1_Swedish_ci
For new versions of mysql such as version 8
Default characterset is utf8mb4 default
Collation is utf8mb4_0900_ai_ci
Fundamentals of Database Administration with MYSQL 65

To find out the default chracterset used by


Your mysql database, simply type the following:

mysql> SHOW VARIABLES LIKE


-> ‘character_set%’;

To find out the collation, simply type the


following:

mysql> SHOW VARIABLES LIKE


-> ‘collation%’;
Fundamentals of Database Administration with MYSQL 66

Character set can be set at 4 levels


1. Server
2. Database
3. Table
4. Column
Fundamentals of Database Administration with MYSQL 67

For Server
We configure the content of my.cnf in your
Database server.
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
Collation-server=utf8mb4_unicode_ci
[mysql]
default-character-set=utf8mb4
Fundamentals of Database Administration with MYSQL 68

To set Characterset and Collation to your


Database you may use the following commands:
CREATE DATABASE databasename
CHARACTER SET uff8mb4
COLLATE utf8mb4_Unicode_ci

To set Characterset and Collation to your


Column you may use the following commands:
CREATE TABLE t1
(col1 varchar(5)
CHARACTER SET Latin1
Collate latin1_german1_ci);
Fundamentals of Database Administration with MYSQL 69

To Modify Existing Database


ALTER DATABASE databasename
CHARACTER SET utf8mb4 COLLATE
Utf8mb4_Unicode_ci;

To Modify Existing Table


ALTER TABLE t1 modify
Col1 VARCHAR(5)
CHARACTER SET latin1
COLLATE latin1_Swedish_ci;
Fundamentals of Database Administration with MYSQL 70
Fundamentals of Database Administration with MYSQL 71

PART 3

DATABASE
NORMALIZATION
Fundamentals of Database Administration with MYSQL 72

Normalization
Database Normalization is the process of
Organizing data into tables in such a way
That the results of using the database
Are always unambiguous and as intended
Fundamentals of Database Administration with MYSQL 73

Unnormalize Data
Fundamentals of Database Administration with MYSQL 74

Normalize Data
Fundamentals of Database Administration with MYSQL 75

Data normalization rules


Fundamentals of Database Administration with MYSQL 76

Data normalization rules

1NF
2NF
3NF
4NF
5NF
Fundamentals of Database Administration with MYSQL 77

Data normalization rules


Find the Error :D
Fundamentals of Database Administration with MYSQL 78

Data normalization Violation of Rules


1Normal Form
Inexplicit Data
Comparing oldest and youngest on the
record
Name Name Age

Person1 Person1 29

Person2 Person2 31

Person3 Person3 26

Person4 Person4 24
Fundamentals of Database Administration with MYSQL 79

Data normalization Violation of Rules


1Normal Form
Combination of Datatypes
Comparing oldest and youngest on the
record
Name Age

Person1 29

Person2 Around 31-32

Person3 26

Person4 24
Fundamentals of Database Administration with MYSQL 80

Data normalization Violation of Rules


1Normal Form
No Primary key
A table without primary key violates the
1st normal form
Fundamentals of Database Administration with MYSQL 81

Data normalization Violation of Rules


1Normal Form
Repeating Groups
Fundamentals of Database Administration with MYSQL 82

Data normalization Violation of Rules


1Normal Form
Repeating Groups

Impractical to query – Display player ID with 7 rings


Terrible database design
Fundamentals of Database Administration with MYSQL 83

Data normalization Violation of Rules


1Normal Form
Repeating Groups

Storing a repeating group of data items


on a single row violates First normal
form
Fundamentals of Database Administration with MYSQL 84

Data normalization Violation of Rules


1Normal Form
Repeating Groups
Fundamentals of Database Administration with MYSQL 85

Data normalization Violation of Rules


Fundamentals of Database Administration with MYSQL 86

Data normalization Violation of Rules


2Normal Form
Must prevent

1. Deletion Anomaly
2. Update Anomaly
3. Insertion Anomaly
Fundamentals of Database Administration with MYSQL 87

Data normalization Violation of Rules


2Normal Form

Identify the
Rating of the player
Fundamentals of Database Administration with MYSQL 88

Data normalization Violation of Rules


2Normal Form

Advance Update Anomaly

Deletion Anomaly No Item Type

Theres a new beginner player name india19 however it is not allowed Insertion Anomaly
to insert because it has no item yet
Fundamentals of Database Administration with MYSQL 89

Data normalization Violation of Rules


2Normal Form
Each non key attribute must depend
on the entire primary key
Fundamentals of Database Administration with MYSQL 90

Data normalization Violation of Rules


3Normal Form
Each non key attribute can also
depend on a non key attribute

4
Presentation title 91
Fundamentals of Database Administration with MYSQL 92

Data normalization Violation of Rules


4Normal Form
Multivalued Dependency
Fundamentals of Database Administration with MYSQL 93

Data normalization Violation of Rules


5 Normal form
Logical Result of Joining a table
Fundamentals of Database Administration with MYSQL 94
Presentation title 95
Fundamentals of Database Administration with MYSQL 96

PART 4

DATABASE
CREATION USING
MYSQL
Fundamentals of Database Administration with MYSQL 97

SOFTWARE INSTALLATION
Database Server
mysql-server
mysql-client
Enable firewall
Fundamentals of Database Administration with MYSQL 98

WHY MYSQL
MySQL allows developers to use
binaries to manipulate database files
even while running. Database files can
also be accessed and manipulated by
alternative processes at runtime.
Conversely, MSSQL doesn't allow any
process to manipulate or access
binaries or database files.
Fundamentals of Database Administration with MYSQL 99

WHY MYSQL
MySQL is an open-source relational
database management system
(RDBMS), while MSSQL Server is a
Microsoft-developed RDBMS.
Fundamentals of Database Administration with MYSQL 100

WHY MYSQL
Fundamentals of Database Administration with MYSQL 101

MYSQL COMMON FUNCTIONS:

lcase() – convert records on a character field into lowercase.


example: select lcase(surname)as lowercase from students;
syntax: select function(field_name)as alias_name from table_name;
ucase() – convert records on a character field into uppercase.
sum() – automatically get the sum of the numerical field.
avg() – automatically calculate and get the average of a numerical field.
count() – use to count number of records present on the table.
concat() – use to merge records coming from different table into a series
of chain. Syntax: select stud_no, concat(sname” , “fname” , “Mi
“ , “)as full_name from students;
Fundamentals of Database Administration with MYSQL 102

min() – displays the least value


max() – displays the highest value

MYSQL COMMON COPERATORS

like – used in a where clause to search for a specific pattern in a column


in – allows you to specify multiple values in a where clause.
and – Displays a record if the conditions separated by AND are true.
or - Displays a record if any of the conditions separated by OR are true.
between – selects a value within a given range. Values can be number,
text or dates.
Sort – use to arrange the result set.
Database Fundamentals 103

Activity:

Assume that there’s a Database Server with a username ICTMC and a


Host Address of 103.152.214.254 with a password of “ICTMC@2024”
To access the aforementioned server follow the steps below:
For Windows User
Ensure that you are connected to the internet then open your cmd or
command prompt terminal as Administrator.
1. In your keyboard press “window + r” in your keyboard then type cmd to
run your command prompt. Once the terminal is already available,
access the database server using the commands below:
ssh –p 2260 [email protected] then enter passcode:
ICTMC@2024 (note: passcode is hidden while typing and type yes if to
record your device ECDSA key)
Database Fundamentals 104

For MAC User


Ensure that you are connected to the internet then type in search bar
terminal then press enter.

1. Once the terminal is already available, access the database server


using the commands below:
ssh –p 2260 [email protected] then enter passcode:
ICTMC@2024 ((note: passcode is hidden while typing and type yes if
to record your device ECDSA key)
Database Fundamentals 105

2. If you access the server successfully open your mysql database account
Using the command below:

Mysql –u [surname_first initial of first name and middle name] –p passcode

Example:
If your fullname is Juan J Dela Cruz your username is
delacruz_jj and the passcode is djj@ictmc

The command will look like this:


-u is for users
-p is for passcode (without space)

mysql –u delacruz_jj –pdjj@ictmc


Database Fundamentals 106

To display the list of database under your account just type the following
below:

show databases;
Database Fundamentals 107

Select your database by typing the command below:

Syntax:
use [database_name];
Note: mysql database name and tables is case sensitive

To display your selected database:


Type the command below:
Database Fundamentals 108

Activity: create a table with 5 records each using the database schema
below:

users orders products

user_id. order_id. product_id.


first_name user product_name
last_name product_ordered description
address total_paid price
email
Database Fundamentals 109

To create table use the following syntax

Table: users

Table: orders
Database Fundamentals 110

Table: products

To describe the properties of your table type the command below:


desc [table_name];
Database Fundamentals 111

Inset record
Syntax: (note if the field use character data type the value to be encode
must be enclosed using double quote “”

Insert into [table_name]


(column1,column2 . . .)
Values
(value1,value2. . .);
Database Fundamentals 112

Display record
To display the table record use select command:

Syntax: select * from table_name;


To generate all records.

To display single column just specify the column name after the select
command.
Database Fundamentals 113

To display record using “like” operator and where clause

Syntax: select * from table_name where column_name like “%”;

“%n” displays all the record of first_name column that ends with letter “n”

“%n%” displays all the record of first_name column with letter “n”
Database Fundamentals 114

To edit column name


Use “ALTER” To modify column name and table

To change column name:

Alter change the column name “email” to ”email_address”


Database Fundamentals 115

To Add new column name


Use “ALTER” To add new column name.
To Add new column:

A new column name contact is added after field address.


Database Fundamentals 116

To Update record
Use “UPDATE” To update existing record.
To update record: (note use a unique reference for the where clause)

A new record is added to column contact_no under user_id 1


Database Fundamentals 117

To CONCAT record
Use “CONCAT” To concat existing record.

To SORT record Ascending Order ASC


Database Fundamentals 118

To SORT record Descending Order desc


Presentation title 119

lcase()
ucase()
avg()
max()
min()

count()
Presentation title 120

To Delete record
Use “DELETE” To Delete existing record.
To Delete record: (note use a unique reference for the where clause)

user_id -1 is now deleted


To delete all records just put * after delete

delete * from users; (note: records cannot be recovered once deleted)


Database Fundamentals 121

To rename table use alter and rename

Table tbl_inventory renamed to inventory


Database Fundamentals 122

To delete table use command drop

Table inventory is deleted.


THANK YOU
Pat Celso T. Agos Jr.
[email protected]
[email protected]

You might also like