0% found this document useful (0 votes)
5 views4 pages

Fundamentals of Database Management Systems 1234

Uploaded by

kbk3moh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
5 views4 pages

Fundamentals of Database Management Systems 1234

Uploaded by

kbk3moh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Fundamentals of Database Management

Systems
Database Design for ABC Supermarket

1. Business Rules Document


Company Overview

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.

2. Entity-Relationship (ER) Diagram


An Entity-Relationship (ER) diagram models the business rules, entities, attributes, and their
relationships. Below is an explanation of the components, followed by a diagram (you may
create the visual using tools like Lucidchart or Draw.io).

Entities and Attributes

 Customer: CustomerID (PK), Name, Email, Phone.


 Order: OrderID (PK), OrderDate, CustomerID (FK).
 Product: ProductID (PK), ProductName, Price, CategoryID (FK), SupplierID (FK).
 Category: CategoryID (PK), CategoryName.
 Supplier: SupplierID (PK), SupplierName, ContactInfo.
 Employee: EmployeeID (PK), Name, DepartmentID (FK).
 Department: DepartmentID (PK), DepartmentName.

Relationships

 A Customer places multiple Orders (1-to-Many).


 An Order includes multiple Products (Many-to-Many, resolved using an intermediate
table).
 A Product belongs to a single Category (1-to-Many).
 A Product is supplied by one Supplier, but a Supplier supplies multiple products (1-to-
Many).
 An Employee works in one Department (1-to-1).

Enhanced Features (EER)

 Specialization/Generalization: Employees are divided into Full-Time and Part-Time,


with unique attributes:
o Full-Time: Salary, Benefits.
o Part-Time: HourlyRate.
 Aggregation: A Sales Transaction combines Customer, Order, and Employee details.

3. Enhanced ER Diagram (EER)


Use an ER modeling tool (e.g., Lucidchart, Microsoft Visio, or hand-drawn) to create the
following diagram:

 Entities with attributes inside rectangles.


 Relationships as diamonds.
 Keys (Primary and Foreign) clearly labeled.
 Specialization (circle to connect generalized entity to specialized entities).
4. Relational Schema
The relational schema translates the ER diagram into database tables. Below are the tables, their
attributes, and relationships.

Tables and Attributes

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).

Primary and Foreign Keys

 Primary Keys: Ensure unique identification of records (e.g., CustomerID, ProductID).


 Foreign Keys: Link related tables (e.g., CustomerID in Order table links to Customer
table).

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)
);

You might also like