Fundamentals of Database Management Systems 1234
Fundamentals of Database Management Systems 1234
Systems
Database Design for ABC Supermarket
ABC Supermarket is a medium-sized retail store offering a wide range of products, such as
groceries, electronics, and household items. It operates through multiple departments, including
Sales, Inventory, and Customer Service. The business serves walk-in and online customers and
requires a database to manage customer orders, employee assignments, inventory tracking, and
supplier information effectively.
Business Rules
1. A customer can place multiple orders, but each order is associated with only one
customer.
Significance: This allows tracking of individual customer purchase histories and enables
better customer relationship management.
2. Each product belongs to one category but can appear in multiple orders.
Significance: Helps with inventory classification, allowing streamlined operations and
analytics.
3. An order must contain at least one product.
Significance: Ensures every order record has meaningful data for processing and
reporting purposes.
4. Employees work in only one department but can assist multiple customers.
Significance: Clarifies organizational structure and employee roles while maintaining
flexibility for customer service tracking.
5. Each supplier can supply multiple products, but a product has only one primary
supplier.
Significance: Tracks supplier accountability for quality and ensures reliable inventory
sourcing.
Relationships
1. Customer:
o CustomerID (PK), Name, Email, Phone.
2. Order:
o OrderID (PK), OrderDate, CustomerID (FK).
3. Product:
o ProductID (PK), ProductName, Price, CategoryID (FK), SupplierID (FK).
4. Category:
o CategoryID (PK), CategoryName.
5. Supplier:
o SupplierID (PK), SupplierName, ContactInfo.
6. Employee:
o EmployeeID (PK), Name, DepartmentID (FK).
7. Department:
o (PK), DepartmentName.
DepartmentID
8. Order_Product (Intermediate Table):
o OrderID (FK), ProductID (FK).
5. SQL Statements
Here’s the SQL code to create the database schema.
sql
Copy code
-- Customer Table
CREATE TABLE Customer (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100),
Phone VARCHAR(15)
);
-- Order Table
CREATE TABLE Order (
OrderID INT PRIMARY KEY,
OrderDate DATE,
CustomerID INT,
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
);
-- Product Table
CREATE TABLE Product (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(100),
Price DECIMAL(10, 2),
CategoryID INT,
SupplierID INT,
FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID),
FOREIGN KEY (SupplierID) REFERENCES Supplier(SupplierID)
);
-- Category Table
CREATE TABLE Category (
CategoryID INT PRIMARY KEY,
CategoryName VARCHAR(100)
);
-- Supplier Table
CREATE TABLE Supplier (
SupplierID INT PRIMARY KEY,
SupplierName VARCHAR(100),
ContactInfo VARCHAR(100)
);
-- Employee Table
CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(100),
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID)
);
-- Department Table
CREATE TABLE Department (
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(100)
);
-- Order_Product Table
CREATE TABLE Order_Product (
OrderID INT,
ProductID INT,
PRIMARY KEY (OrderID, ProductID),
FOREIGN KEY (OrderID) REFERENCES Order(OrderID),
FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
);