Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Question 1: Design an ERD

The Blood Donation Management System (BDMS) is a comprehensive database designed to manage
the process of blood donation and distribution efficiently.

Entities:

 Donor: Captures detailed information about donors, including their DonorID, Name, Contact
Information, Blood Type, and Donation History.
 Blood Bank: Contains details about the various blood banks and centers participating in the
donation process. Attributes include BankID, Name, Address, and Contact Information.
 Blood Type: Represents the different blood types available for donation. Attributes include
TypeID and BloodType.
 Donation Event: Captures information about specific donation events organized by blood
banks. Attributes include EventID, Date, Location, and Blood Bank involved.
 Blood Donation: Central entity that tracks individual donations made by donors. Attributes
include DonationID, DonorID, BankID, DonationDate, and Quantity.
 Blood Component: Contains details about the various components of blood, such as red
blood cells, platelets, and plasma. Attributes include ComponentID, ComponentName, and
Blood Type.
 Blood Collection: Records information about the collection process, including CollectionID,
CollectionDate, and CollectionSite.
 Blood Screening: Tracks details about the screening process, including ScreeningID,
ScreeningDate, and ScreeningResult.
 Blood Storage: Stores information about blood storage, including StorageID, StorageLocation,
and ExpiryDate.

Relationships:

 Donor to Blood Donation: A donor can make multiple donations over time.
 Blood Bank to Donation Event: A blood bank organizes multiple donation events.
 Blood Bank to Blood Donation: A blood bank receives donations from multiple donors.
 Blood Donation to Blood Type: Each donation is associated with a specific blood type.
 Blood Donation to Blood Component: A donation can be divided into multiple blood
components.
 Blood Donation to Blood Screening: Each donation undergoes a screening process.
 Blood Donation to Blood Storage: Donated blood is stored for future use.

This comprehensive ERD allows for detailed tracking and management of the blood donation
process, from the initial donation event to the final storage and distribution of blood and its
components.

Question 2: Normalize the ERD in Question 1 to achieve at least 3NF.


Convert the ERD above to the schema diagram.
Question 3:
a. Used the provided database, created a database, and exported the
schema diagram.
b. Answer these queries below:
 Select the names of customers who have not placed any orders.
SELECT CustomerName
FROM Customers
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);

 Display a list of categories along with the count of products in each category.

SELECT c.CategoryName, COUNT(p.ProductID) AS ProductCount


FROM Categories c
LEFT JOIN Products p ON c.CategoryID = p.CategoryID
GROUP BY c.CategoryName;
 List the top 10 most expensive products, ordered by price.

SELECT TOP 10 ProductName, Price


FROM Products
ORDER BY Price DESC;

 Find the total quantity of each product sold.

SELECT p.ProductName, SUM(od.Quantity) AS TotalQuantitySold


FROM OrderDetails od
JOIN Products p ON od.ProductID = p.ProductID
GROUP BY p.ProductName;
 Show the average order value for each customer.

SELECT c.CustomerName, AVG(od.Quantity * p.Price) AS AverageOrderValue


FROM Orders o
JOIN OrderDetails od ON o.OrderID = od.OrderID
JOIN Products p ON od.ProductID = p.ProductID
JOIN Customers c ON o.CustomerID = c.CustomerID
GROUP BY c.CustomerName;
 Retrieve the names of employees who have taken orders.

SELECT DISTINCT e.FirstName, e.LastName


FROM Employees e
JOIN Orders o ON e.EmployeeID = o.EmployeeID;
 Find the total number of orders placed by each customer.

SELECT c.CustomerName, COUNT(o.OrderID) AS TotalOrders


FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName;
 List the names of customers who have placed orders after a specific date.
DECLARE @SpecificDate DATETIME = '1996-07-11';
SELECT DISTINCT c.CustomerName
FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
WHERE o.OrderDate > @SpecificDate;
 Show the orders placed on a particular date.
DECLARE @ParticularDate DATETIME = '1996-08-21';

SELECT o.OrderID, c.CustomerName, o.OrderDate


FROM Orders o
JOIN Customers c ON o.CustomerID = c.CustomerID
WHERE o.OrderDate = @ParticularDate;
 Display the customers' names and the number of orders they have placed.

SELECT c.CustomerName, COUNT(o.OrderID) AS NumberOfOrders


FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName;
 Find the total revenue generated from each product.

SELECT p.ProductName, SUM(od.Quantity * p.Price) AS TotalRevenue


FROM OrderDetails od
JOIN Products p ON od.ProductID = p.ProductID
GROUP BY p.ProductName;
 Show the names of customers who have placed orders from more than one employee.

SELECT c.CustomerName
FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName
HAVING COUNT(DISTINCT o.EmployeeID) > 1;
 Retrieve the total quantity of each product sold in a specific month.
DECLARE @Month INT = 08;
DECLARE @Year INT = 1996;

SELECT p.ProductName, SUM(od.Quantity) AS TotalQuantitySold


FROM OrderDetails od
JOIN Products p ON od.ProductID = p.ProductID
JOIN Orders o ON od.OrderID = o.OrderID
WHERE MONTH(o.OrderDate) = @Month AND YEAR(o.OrderDate) = @Year
GROUP BY p.ProductName;
 List the products with a quantity of less than 10 in stock.

SELECT p.ProductName
FROM Products p
LEFT JOIN (
SELECT ProductID, SUM(Quantity) AS TotalQuantitySold
FROM OrderDetails
GROUP BY ProductID
) AS Sold ON p.ProductID = Sold.ProductID
WHERE COALESCE(Sold.TotalQuantitySold, 0) < 10;
 Show the number of orders placed by each employee.

SELECT e.FirstName, e.LastName, COUNT(o.OrderID) AS NumberOfOrders


FROM Employees e
JOIN Orders o ON e.EmployeeID = o.EmployeeID
GROUP BY e.FirstName, e.LastName;

You might also like