0% found this document useful (0 votes)
11 views12 pages

SQL Assignment 1

The document outlines a Disaster Relief Database designed to manage and track individuals affected by natural disasters, the types of disasters, and the aid distributed. It details the normalization process of the database from an unnormalized form to third normal form, including the creation of tables for individuals, disasters, aid types, and aid distribution. Additionally, it provides SQL code for database creation, data insertion, and various queries for retrieving information from the database.

Uploaded by

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

SQL Assignment 1

The document outlines a Disaster Relief Database designed to manage and track individuals affected by natural disasters, the types of disasters, and the aid distributed. It details the normalization process of the database from an unnormalized form to third normal form, including the creation of tables for individuals, disasters, aid types, and aid distribution. Additionally, it provides SQL code for database creation, data insertion, and various queries for retrieving information from the database.

Uploaded by

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

SQL ASSIGNMENT:DISASTER RELIEF

DATABASE
YOGESHWAR
22-UCC-042

SCENARIO DESCRIPTION
Disaster Relief Database –
In recent years, natural disasters like floods, earthquakes, and cyclones have affected
several regions, displacing families and causing severe damage to life and property. To
manage the relief efforts efficiently, the government and non-governmental organizations
(NGOs) have come together to create a Disaster Relief Management System.
This system is responsible for tracking:
● Individuals affected by disasters.
● Types of disasters and their locations.
● Relief aid distributed, including food, water, shelter, and medical assistance.
● Amount of aid provided to each individual.
Affected Individuals
Each individual affected by a disaster is recorded in the system with personal details like
name, age, and gender. An individual may be affected by more than one disaster and may
receive multiple types of aid.
Disaster Events
Each disaster is recorded with a unique ID, type (e.g., flood, earthquake), the location it
occurred, and the date. This allows the system to track which regions were affected and
what kind of aid they required.
Types of Aid
Aid is categorized into several types:
● Food
● Water
● Shelter
● Medical
Each aid type is uniquely identified and can be distributed to any affected individual
depending on their need and the severity of the disaster.
Aid Distribution
Every time aid is distributed, the system logs:
● The individual who received the aid
● The disaster related to that aid
● The type of aid provided
● The amount of aid (in units or value)
This ensures transparency, helps avoid duplication, and allows decision-makers to identify
gaps in relief efforts.

1. Unnormalized Table (UNF)


Table Name: DisasterReliefRecords_UNF
A
ReliefI DisasterTy Locati Dat IndividualNa Gend AidType AidAmoun
g
D pe on e me er s ts
e
202
Food,
5- 3 100, 50,
1 Flood City A Alice Thomas F Water,
03- 4 300
Shelter
01
202
5- Ramesh 4 Medical,
2 Earthquake City B M 500, 50
03- Kumar 5 Water
05
202
5- 2 Food,
3 Flood City A Meena Patel F 100, 300
03- 9 Shelter
01
4 Cyclone City C 202 John Roy 5 M Water, 50, 100
5- 0 Food
03-
A
ReliefI DisasterTy Locati Dat IndividualNa Gend AidType AidAmoun
g
D pe on e me er s ts
e
10
202
Food,
5- 4 100, 300,
5 Flood City D Anita Joseph F Shelter,
03- 1 500
Medical
12
202
5- 3
6 Earthquake City B Suresh Pillai M Medical 500
03- 6
05
202
5- 2
7 Cyclone City C Kiran Dev M Water 50
03- 5
10
202
5- 3 Food,
8 Flood City A Farah Sheikh F 100, 50
03- 8 Water
01
202
5- 3 Shelter,
9 Cyclone City C Asha Menon F 300, 500
03- 1 Medical
10
202
Water,
5- 4 50, 100,
10 Earthquake City B Sanjay Rao M Food,
03- 7 300
Shelter
05
Problem: AidTypes and AidAmounts are multivalued and repeating groups.

2. Normalization
First Normal Form (1NF)
Remove repeating groups. Create one row per aid type and amount.
Table Name: DisasterRelief_1NF
A
ReliefI DisasterTy Locati IndividualNa Gend AidTy AidAmou
Date g
D pe on me er pe nt
e
2025- 3
1 Flood City A Alice Thomas F Food 100
03-01 4
2025- 3
1 Flood City A Alice Thomas F Water 50
03-01 4
2025- 3 Shelte
1 Flood City A Alice Thomas F 300
03-01 4 r
... ... ... ... ... ... ... ... ...
(Continued for all 10 records.)

Second Normal Form (2NF)


Remove partial dependencies. Split into separate tables.
● Individuals Table (IndividualID as PK)
● Disasters Table (DisasterID as PK)
● Aid Table (with FK to both Individual and Disaster)
Individuals
A
IndividualI Gend
Name g
D er
e
3
IND1 Alice Thomas F
4
Ramesh 4
IND2 M
Kumar 5
... ... ... ...
Disasters
DisasterI DisasterTy Locati
Date
D pe on
2025-03-
D1 Flood City A
01
2025-03-
D2 Earthquake City B
05
DisasterI DisasterTy Locati
Date
D pe on
... ... ... ...
AidDistribution
AidI Individual Disaster AidTy AidAmou
D ID ID pe nt
A1 IND1 D1 Food 100
A2 IND1 D1 Water 50
... ... ... ... ...

Third Normal Form (3NF)


Remove transitive dependencies. Separate Aid Types into their own table.
AidTypes
AidTypeI AidTy
D pe
T1 Food
T2 Water
Shelte
T3
r
Medic
T4
al
Modified AidDistribution
AidI Individual Disaster AidType AidAmou
D ID ID ID nt
A1 IND1 D1 T1 100
A2 IND1 D1 T2 50
... ... ... ... ...

CODES
create database D1;
drop database d1;
use d1;
Table Creation;

CREATE TABLE Individuals (


IndividualID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Gender CHAR(1)
);

CREATE TABLE Disasters (


DisasterID VARCHAR(10) PRIMARY KEY,
DisasterType VARCHAR(50),
Location VARCHAR(100),
Date DATE
);

CREATE TABLE AidTypes (


AidTypeID VARCHAR(10) PRIMARY KEY,
AidType VARCHAR(50)
);

CREATE TABLE AidDistribution (


AidID VARCHAR(10) PRIMARY KEY,
IndividualID VARCHAR(10),
DisasterID VARCHAR(10),
AidTypeID VARCHAR(10),
AidAmount INT,
FOREIGN KEY (IndividualID) REFERENCES Individuals(IndividualID),
FOREIGN KEY (DisasterID) REFERENCES Disasters(DisasterID),
FOREIGN KEY (AidTypeID) REFERENCES AidTypes(AidTypeID)
);

-- Data Insertion

-- Aid Types
INSERT INTO AidTypes VALUES
('T1', 'Food'),
('T2', 'Water'),
('T3', 'Shelter'),
('T4', 'Medical');

-- Disasters
INSERT INTO Disasters VALUES
('D1', 'Flood', 'City A', '2025-03-01'),
('D2', 'Earthquake', 'City B', '2025-03-05'),
('D3', 'Cyclone', 'City C', '2025-03-10'),
('D4', 'Flood', 'City D', '2025-03-12');

-- Individuals
INSERT INTO Individuals VALUES
('IND1', 'Alice Thomas', 34, 'F'),
('IND2', 'Ramesh Kumar', 45, 'M'),
('IND3', 'Meena Patel', 29, 'F'),
('IND4', 'John Roy', 50, 'M'),
('IND5', 'Anita Joseph', 41, 'F'),
('IND6', 'Suresh Pillai', 36, 'M'),
('IND7', 'Kiran Dev', 25, 'M'),
('IND8', 'Farah Sheikh', 38, 'F'),
('IND9', 'Asha Menon', 31, 'F'),
('IND10', 'Sanjay Rao', 47, 'M');

-- Aid Distribution
INSERT INTO AidDistribution VALUES
('A1', 'IND1', 'D1', 'T1', 100),
('A2', 'IND1', 'D1', 'T2', 50),
('A3', 'IND1', 'D1', 'T3', 300),
('A4', 'IND2', 'D2', 'T4', 500),
('A5', 'IND2', 'D2', 'T2', 50),
('A6', 'IND3', 'D1', 'T1', 100),
('A7', 'IND3', 'D1', 'T3', 300),
('A8', 'IND4', 'D3', 'T2', 50),
('A9', 'IND4', 'D3', 'T1', 100),
('A10', 'IND5', 'D4', 'T1', 100),
('A11', 'IND5', 'D4', 'T3', 300),
('A12', 'IND5', 'D4', 'T4', 500),
('A13', 'IND6', 'D2', 'T4', 500),
('A14', 'IND7', 'D3', 'T2', 50),
('A15', 'IND8', 'D1', 'T1', 100),
('A16', 'IND8', 'D1', 'T2', 50),
('A17', 'IND9', 'D3', 'T3', 300),
('A18', 'IND9', 'D3', 'T4', 500),
('A19', 'IND10', 'D2', 'T2', 50),
('A20', 'IND10', 'D2', 'T1', 100),
('A21', 'IND10', 'D2', 'T3', 300);

-- Queries
-- 1. Individuals who received Medical aid
SELECT i.Name, a.AidAmount
FROM Individuals i
JOIN AidDistribution ad ON i.IndividualID = ad.IndividualID
JOIN AidTypes a ON ad.AidTypeID = a.AidTypeID
WHERE a.AidType = 'Medical';

-- 2. Total aid distributed per disaster


SELECT d.DisasterType, d.Location, SUM(ad.AidAmount) AS TotalAid
FROM AidDistribution ad
JOIN Disasters d ON ad.DisasterID = d.DisasterID
GROUP BY d.DisasterType, d.Location;

-- 3. Individuals ordered by total aid received


SELECT i.Name, SUM(ad.AidAmount) AS TotalAid
FROM AidDistribution ad
JOIN Individuals i ON ad.IndividualID = i.IndividualID
GROUP BY i.Name
ORDER BY TotalAid DESC;

-- 4. Distinct types of aid provided


SELECT DISTINCT AidType FROM AidTypes;

-- 5. Individuals who received more than 400 total aid


SELECT i.Name, SUM(ad.AidAmount) AS TotalAid
FROM AidDistribution ad
JOIN Individuals i ON ad.IndividualID = i.IndividualID
GROUP BY i.Name
HAVING SUM(ad.AidAmount) > 400;

OUTPUT:

You might also like