DBS Oel
DBS Oel
Members Qalam ID
Muhammad Ahmad Raza 466747
Anas Rehman 464092
Usayd bin Wasim 455549
Lab 12: Open Ended Lab
Introduction
This lab is Open Ended Lab a complete scenario is given and you are required to propose the
solutions as per your understandings.
Objectives
Objective of this lab is to understand the scenario, make ERD, write DDL , populate data through
DML and Execute DRL for reports.
1. Customer
Name
Contact Details
Phone Number
2. Pet
Name
Breed
Age
Customer Id
3. Visit
Pet Id
Visit Id
Total Cost
4. Treatment
Visit Id
Treatment Name
Description
Cost
5. Bill
Visit Id
Total Amount
Details
6. Medication
Treatment Id
Medication Name
Dosage
Price
Entity Constraints
1. Customer:
2. Pet:
4. Treatment:
5. Medication:
6. Bill:
Relationship Constraints
1. Customer ↔ Pet:
2. Pet ↔ Visit:
3. Visit ↔ Treatment:
4. Treatment ↔ Medication:
5. Visit ↔ Bill:
Constraint: A bill must correspond to a single visit and include details of all associated
treatments and costs.
Other Constraints
Non-Null Constraints:
o All primary and foreign keys must not be null.
o Essential attributes like Name, Cost, and TotalAmount must not be null.
Unique Constraints:
o Primary keys (CustomerID, PetID, VisitID, TreatmentID, MedicationID, BillID) must be
unique.
Referential Integrity:
o Foreign keys (CustomerID in Pet, PetID in Visit, VisitID in Treatment, TreatmentID in
Medication, VisitID in Bill) must reference existing primary keys in their respective parent
tables.
5: Populate the database with 3 owners, 5 pets, 3 treatments, 7 medicines, 1 old visit and 1
current visit
DML Statements:
insert into Customer (Name, ContactDetails, PhoneNumber)
values
('Ahmad', '123-456-7890', '0337-8376282'),
('Anas', '987-654-3210', '0327-9119401'),
('Ali', '456-789-1234', '0301-5271892');
CODE:
select TotalAmount from Bill where VisitID = 1;
OUTPUT:
b: bill with details of the current visit
CODE:
select TotalAmount from Bill where VisitID = 2;
OUTPUT:
d: Identify the Pet having maximum distinct treatments along with treatment name.
CODE:
select p.Name AS PetName, t.TreatmentName
from Pet p
join Treatment t on p.PetID = t.VisitID
where p.PetID = (
select PetID
from (
select p.PetID, count(distinct t.TreatmentName) as
DistinctTreatmentCount
from Pet p
join Treatment t on p.PetID = t.VisitID
group by p.PetID
order by DistinctTreatmentCount DESC
limit 1
) as MaxTreatments
);
OUTPUT:
Deliverables:
Provide a complete report having ERD, DDL, DML, DRL and snapshot of results.
Work Done:
ERD done by Anas Rehman.
DDL done by Usayd bin Wasim.
DML and DRL done by Muhammad Ahmad Raza.