Database Lab3
Database Lab3
Database Lab3
3.1 Objectives:
• To know about the First Normalization in Database Management System.
• To learn about how to create database and how to perform some simple
mathematical calculations by using ‘MySQL Workbench.’
• To learn about how to create table and how to perform some simple
operations on the table by using ‘MySQL Workbench.’
3.2 Theory:
Normalization: Normalization is the process of minimizing redundancy from a relation
or set of relations. Redundancy in relation may cause insertion, deletion and update
anomalies. So, it helps to minimize the redundancy in relations. Normal forms are used
to eliminate or reduce redundancy in database tables.
First Normal Form (1NF): If a relation contains a composite or multi-valued attribute,
it violates the first normal form, or the relation is in first normal form if it does not
contain any composite or multi-valued attribute. A relation is in first normal form if
every attribute in that relation is singled valued attribute.
A table is in 1 NF if: There are only Single Valued Attributes. Attribute Domain does
not change. There is a unique name for every Attribute/Column. The order in which
data is stored does not matter.
SQL: SQL (structured query language) is a language for specifying the organization of
databases (collections of records). Databases organized with SQL are called relational,
because SQL provides the ability to query a database for information that falls in a given
relation.
3.3 SQL Code and Outputs:
Task 01: Create a table and split this table
Code:
create table orginial_table(
id INT PRIMARY KEY,
name varchar(50),
age INT);
INSERT INTO orginial_table(id,name,age)values
(10,'Fuad',30),
(20,'Promy',40),
(30,'Jakir',20),
(40,'Ritu',35),
(50,'Antu',18);
Output:
10
Figure 1: Original table Figure 2: Table t1 Figure 3: Table t2
11
Task 03: Splitting the main table for first phone number
Code:
create table n1f as SELECT id,name, age, SUBSTRING_INDEX(mobile, ',', 1)
AS mobile1 from updates_orginial_table;
select * from n1f order by id;
Output:
Task 04: Splitting the main table for second phone number
Code:
create table n1f2 as SELECT id,name, age, SUBSTRING_INDEX(mobile, ',', -
1)
AS mobile2 from updates_orginial_table where mobile LIKE '%,%';
select * from n1f2 order by id;
Output:
Task 05: Merge the splitted tables for every single phone number
Code:
SELECT * FROM n1f
UNION ALL
SELECT * FROM n1f2 order by id;
Output:
12
3.4 Discussion & Conclusion:
In this lab experiment, we delved into the concept of normalization in database
management systems (DBMS). Normalization is a crucial process that aims to minimize
redundancy and dependency in a database by organizing data into separate tables. It
involves a series of rules, known as normal forms, which guide the structuring of the
database to ensure data integrity and efficiency. Our focus was primarily on achieving the
first normal form (1NF), which necessitates that each column in a table contains atomic
values, and there are no repeating groups or arrays. To accomplish this, we systematically
divided the initial dataset into two distinct tables, adhering to the principles of 1NF. This
entailed identifying and isolating distinct pieces of information to maintain a clean and
well-organized database structure. By doing so, we aimed to eliminate data redundancy
and minimize the chances of update anomalies, ultimately contributing to a more robust
and efficient database system
13