0% found this document useful (0 votes)
16 views29 pages

Database project

The document outlines a project to develop an Online Food Ordering Database Management System for Injibara University, aimed at streamlining food orders and enhancing user experience through various modules for users, admins, and restaurants. It details the core functionalities, database design, technologies used, and educational goals, emphasizing practical application of theoretical knowledge in database management and software development. The project also highlights its significance in fostering teamwork, problem-solving, and preparing students for real-world applications in software development.

Uploaded by

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

Database project

The document outlines a project to develop an Online Food Ordering Database Management System for Injibara University, aimed at streamlining food orders and enhancing user experience through various modules for users, admins, and restaurants. It details the core functionalities, database design, technologies used, and educational goals, emphasizing practical application of theoretical knowledge in database management and software development. The project also highlights its significance in fostering teamwork, problem-solving, and preparing students for real-world applications in software development.

Uploaded by

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

�Project Overview

Project Title: Online Food Ordering Database Management System


Context: University-level academic project (focused on Database Systems)

Project Title:

Online Food Ordering System – Database Management Project In Injibara University

Objective:

To create a centralized and efficient system that manages food orders online, tracks real-time
customer orders, maintains restaurant data, and ensures smooth transactions between customers
and restaurants.

�Core Modules

1. User Module (Customers):


o Registration/Login
o Browse restaurants and menus
o Place, track, and cancel orders
o Make online payments
2. Admin Module:
o Manage user accounts
o Add/update/delete restaurants and menu items
o View orders, sales reports, and feedback
3. Restaurant Module (Vendor):
o Manage their profile and menu
o Accept or reject orders
o Track delivery status
4. Order Management:
o Track order lifecycle (placed → confirmed → prepared → delivered)
o Notify users via email/SMS (optional)
5. Payment System:
o Handle payments securely
o Generate receipts/invoices

�Database Design Overview

Key Tables:

 Users (UserID, Name, Email, Password, Address)


 Restaurants (RestaurantID, Name, Address, Contact)
 Menu_Items (ItemID, RestaurantID, ItemName, Description, Price)
 Orders (OrderID, UserID, RestaurantID, OrderDate, Status, TotalAmount)
 Order_Details (OrderDetailID, OrderID, ItemID, Quantity, Price)
 Payments (PaymentID, OrderID, PaymentDate, Amount, PaymentMethod)
 Feedback/Reviews (ReviewID, UserID, RestaurantID, Rating, Comment)

�Benefits

 Faster and convenient ordering process


 Reduced manual errors in order handling
 Data-driven insights for restaurants and admins
 Better customer satisfaction and engagement

�Technologies Used (Typical Stack)

 Frontend: HTML/CSS, JavaScript, React or Angular (optional)


 Backend: PHP, Python (Django/Flask), or Node.js
 Database: MySQL, PostgreSQL, or MongoDB
 Tools: XAMPP/WAMP for local hosting, Git for version control

�Project Objective

The main objective of the Online Food Ordering Database Management System in Injibara
university is to design and implement a robust, efficient, and user-friendly system that
manages the end-to-end process of online food ordering—streamlining the operations for
students, cafteria managers, and system administrators through an integrated database-driven
platform.

�Specific Goals

1. Automate the Ordering Process


o Allow users(students) to view menus and place orders online.
o Eliminate manual handling of food orders.
2. Centralized Database Management
o Maintain consistent and accurate data for users(students), cafeterias, orders, and
payments in a centralized database.
o Enable secure data access and updates with minimal redundancy.
3. Improve User(student) Convenience
o Provide a smooth user experience for browsing cafeterias, selecting items, and
tracking orders.
4. Real-Time Order Tracking
o Enable students to track the status of their orders in real time.
5. Restaurant and Menu Management
o Allow cafeterias to manage their profiles, update menu items, and monitor
customer feedback.
6. Secure and Reliable Payment Integration
o Include safe transaction handling through online payment options.
7. Reporting and Analytics (Admin)
o Generate sales, customer, and performance reports for administrative review.
8. Scalability and Extensibility
o Build a scalable system that can be expanded to include features like delivery
tracking, mobile integration, and AI-based recommendations.

�Educational Goals (University Perspective)

 Apply database design principles (ER modeling, normalization).


 Practice backend and frontend development integration.
 Learn about CRUD operations using SQL or NoSQL databases.
 Understand client-server architecture.
 Develop testing, debugging, and documentation skills.
 Foster teamwork and project management (if group-based).

Project Objective

The main objective of the Online Food Ordering Database Management System is to design and
implement a robust, efficient, and user-friendly system that manages the end-to-end process of online
food ordering—streamlining the operations for customers, restaurant managers, and system
administrators through an integrated database-driven platform.

�Specific Goals

1. Automate the Ordering Process


o Allow users to view menus and place orders online.
o Eliminate manual handling of food orders.
2. Centralized Database Management
o Maintain consistent and accurate data for users, restaurants, orders, and payments in a
centralized database.
o Enable secure data access and updates with minimal redundancy.
3. Improve User Convenience
o Provide a smooth user experience for browsing restaurants, selecting items, and
tracking orders.
4. Real-Time Order Tracking
o Enable customers to track the status of their orders in real time.
5. Restaurant and Menu Management
o Allow restaurants to manage their profiles, update menu items, and monitor customer
feedback.
6. Secure and Reliable Payment Integration
o Include safe transaction handling through online payment options.
7. Reporting and Analytics (Admin)
o Generate sales, customer, and performance reports for administrative review.
8. Scalability and Extensibility
o Build a scalable system that can be expanded to include features like delivery tracking,
mobile integration, and AI-based recommendations.

�Educational Goals (University Perspective)

 Apply database design principles (ER modeling, normalization).


 Practice backend and frontend development integration.
 Learn about CRUD operations using SQL or NoSQL databases.
 Understand client-server architecture.
 Develop testing, debugging, and documentation skills.
 Foster teamwork and project management (if group-based).

Would you like a sample project abstract or documentation template for submission?

4o
The significance of an Online Food Ordering Database Management System project in a university
setting goes beyond just building a functional application—it plays a key role in academic development,
skill-building, and real-world application. Here's a breakdown:

�Significance in University Context

1. Practical Application of Theoretical Knowledge


 Students get to apply concepts from courses such as Database Management Systems (DBMS),
Software Engineering, Web Development, and System Analysis and Design in a real-world
scenario.
 Encourages hands-on learning through a full-stack project experience.

2. Understanding of End-to-End Software Development

 Covers the complete SDLC (Software Development Life Cycle): planning, designing,
implementing, testing, and deployment.
 Teaches how databases interact with frontend and backend logic.

3. Team Collaboration and Project Management

 Often developed in groups, the project fosters teamwork, communication, and version control
using tools like Git.
 Simulates real industry environments.

4. Problem-Solving and Critical Thinking

 Involves solving real-world problems like data inconsistency, user authentication, concurrent
access, and secure transactions.

5. Portfolio and Career Relevance

 Acts as a strong portfolio project for job or internship applications in software development,
web development, or data management.
 Demonstrates practical skills to potential employers.

6. Entrepreneurial and Innovation Opportunities

 Encourages students to think about business logic, user experience, and market needs—which
can be a foundation for startups or freelance work.

7. Preparation for Final Year Projects and Research

 Builds a solid foundation for more complex final-year projects involving e-commerce, AI-driven
recommendation systems, or cloud-based applications.

In summary, this project is significant because it bridges academic knowledge and real-world
application, equipping students with both technical and soft skills needed in the industry.

Feasibility Study
1. Technical Feasibility

 Database System Compatibility:


o Relational databases like MySQL, PostgreSQL, or SQLite are ideal for structured data
such as users, restaurants, menu items, and orders.
o Easily supports normalization, indexing, foreign keys, and constraints.
 Skill Set Required:
o Students learn SQL, ER modeling, CRUD operations, and relational schema design.
o Tools like phpMyAdmin, pgAdmin, or SQLiteStudio can be used.
 Infrastructure:
o The system can run locally using XAMPP/WAMP/LAMP stacks.
o Lightweight setup, suitable for university labs or personal computers.
Functional Requirements

Project: Online Food Ordering Database Management System


Focus: What the system should do (functionality)
Context: University DBMS Project

1. User Management

What the system should do:

 Allow users to register and log in.


 Differentiate between admin, restaurant, and customer roles.
 Enable users to update their profiles.

Database Tables:
Users, Roles

Tools:

 DBMS: MySQL / PostgreSQL / SQLite


 Backend: PHP, Python (Flask/Django), or Node.js
 Authentication Libraries: bcrypt, JWT (optional)

2. Restaurant and Menu Management

What the system should do:

 Admin can add or approve restaurants.


 Restaurants can add/update/delete menu items.
 Customers can view menus by restaurant and category.

Database Tables:
Restaurants, Menu_Items, Categories

Tools:

 DBMS: MySQL
 UI: HTML/CSS, Bootstrap
 CRUD Interfaces: PHPMyAdmin, custom admin panel
3. Order Management

What the system should do:

 Allow customers to select items and place orders.


 Track orders with statuses: Placed, Confirmed, Preparing, Delivered.
 Allow restaurants to accept/reject orders.

Database Tables:
Orders, Order_Details, Order_Status, Users, Menu_Items

Tools:

 Backend: Python (Flask), PHP (Laravel), Node.js


 JavaScript for dynamic cart and order updates
 SQL joins for retrieving order summaries

4. Payment Handling

What the system should do:

 Simulate or record payment methods (e.g., COD, Card).


 Store transaction details.

Database Tables:
Payments, Orders

Tools:

 Database functions for triggers or logging


 Optional: Integrate with mock payment gateway APIs

5. Review and Rating System

What the system should do:

 Allow customers to rate restaurants and leave feedback.


 Display average ratings per restaurant.
Database Tables:
Reviews, Users, Restaurants

Tools:

 SQL Aggregation (AVG, COUNT)


 Frontend star-rating plugins (optional)

6. Reporting and Administration

What the system should do:

 Admin can view reports: total users, total sales, order trends.
 Generate summaries using aggregate queries.

Database Tables:
Users, Orders, Payments, Menu_Items

Tools:

 SQL queries (GROUP BY, COUNT, SUM)


 Chart libraries: Chart.js, Google Charts (optional)

7. Security Functions

What the system should do:

 Enforce role-based access control.


 Secure sensitive data (e.g., hash passwords).
 Sanitize user inputs to prevent SQL injection.

Database Features:

 Constraints, triggers, stored procedures


 Foreign key integrity

Tools:

 Hashing libraries (bcrypt)


 SQL parameterized queries
�Suggested Tools Overview

Layer Tools/Technologies

Database MySQL, PostgreSQL, SQLite

Backend PHP, Python (Django/Flask), Node.js

Frontend HTML, CSS, Bootstrap, JavaScript

Admin Tools phpMyAdmin, custom dashboards

Version Control Git, GitHub

Testing Postman (for APIs), Manual SQL testing

Reporting SQL Queries, Chart.js (optional)

Would you like a sample schema or ER diagram that aligns with these functional requirements?

4o

�Non-Functional Requirements

Project: Online Food Ordering Database Management System


Context: University Database Systems Project

�1. Performance Requirements

These requirements ensure the system responds efficiently under expected workloads.

 Query Optimization:
o SQL queries must be optimized to retrieve data with minimal delay (e.g., using indexes
on UserID, OrderID, RestaurantID).
 Response Time:
o The system should respond to user queries (e.g., order status, menu listings) within 2–
3 seconds under normal load.
 Concurrent Access:
o The database should support multiple users placing orders simultaneously without
conflict or data loss (use of transaction management or isolation levels).
 Scalability (Academic-Level):
o Though a small-scale project, the system should be designed to handle hundreds of
records and allow for easy future expansion.

�2. Usability Requirements

These ensure the system is easy to use, understand, and navigate, especially by non-technical users.

 User Interface Design:


o Should be intuitive and user-friendly for students and evaluators. Simple navigation
between restaurants, menus, and order placement.
 Role-Based Navigation:
o Users (Customer, Admin, Restaurant) should only see features relevant to their roles
to reduce confusion.
 Error Handling:
o Clear messages should be shown for invalid data entries (e.g., entering letters in a
quantity field).
 Accessibility:
o System should support basic keyboard navigation and be usable across devices
(desktop and mobile view, if applicable).

�3. Security Requirements

These focus on protecting the database and user data from unauthorized access or misuse.

 User Authentication and Authorization:


o Only registered users can access the system. Each role has permissions enforced at
both the application and database level.
 Password Management:
o Passwords should be stored in hashed format (e.g., using bcrypt or SHA algorithms).
 SQL Injection Protection:
o Input fields must be sanitized to prevent SQL injection attacks.
 Data Integrity Constraints:
o Use primary keys, foreign keys, NOT NULL, and CHECK constraints to ensure data
consistency and correctness.
 Session Management (Optional):
o Secure session tracking (e.g., session timeout, logout features) to avoid unauthorized
access.
 Backup and Recovery:
o Implement a backup mechanism (manual or automated) for restoring data in case of
corruption or loss.

�Summary Table
Category Requirement

Performance Fast query execution, supports concurrent users, scalable

Usability Simple UI, role-based navigation, error feedback

Security Hashed passwords, SQL injection protection, role-based access

Entity-Relationship Diagram (ERD): Explanation

�Entities and Attributes

1. User
o UserID (PK)
o Name
o Email
o Password
o Phone
o Role (Customer, Restaurant, Admin)
2. Restaurant
o RestaurantID (PK)
o UserID (FK from User)
o RestaurantName
o Address
o Phone
o Status (Approved, Pending)
3. MenuItem
o ItemID (PK)
o RestaurantID (FK)
o ItemName
o Description
o Price
o Category
4. Order
o OrderID (PK)
o UserID (FK from User - customer)
o RestaurantID (FK)
o OrderDate
o TotalAmount
o Status (Placed, Confirmed, Delivered, Canceled)
5. OrderDetail
o OrderDetailID (PK)
o OrderID (FK)
o ItemID (FK)
o Quantity
o Subtotal
6. Payment
o PaymentID (PK)
o OrderID (FK)
o Amount
o PaymentDate
o PaymentMethod (COD, Online)
o PaymentStatus
7. Review
o ReviewID (PK)
o UserID (FK)
o RestaurantID (FK)
o Rating (1–5)
o Comment
o ReviewDate

�Relationships Overview

 User —< Restaurant: One user (restaurant owner) can manage one or more restaurants.
 Restaurant —< MenuItem: One restaurant can offer many menu items.
 User —< Order: One user (customer) can place many orders.
 Restaurant —< Order: One restaurant can receive many orders.
 Order —< OrderDetail >— MenuItem: Many-to-many between orders and menu items, with
quantities and prices.
 Order — Payment: One order has one payment record.
 User —< Review >— Restaurant: Many-to-many, one customer can review many restaurants.

�Sample ERD Structure (Textual Form)


Css

[User]───<owns>───[Restaurant]───<offers>───[MenuItem]
│ │
<places> <receives>
│ │
[Order]───<contains>───[OrderDetail]───<refers to>───[MenuItem]

<pays>

[Payment]
[User]───<writes>───[Review]───<about>───[Restaurant]

�Normalization in Database Design

Project: Online Food Ordering Database Management System


Level: University – Database Systems
Objective: To ensure the database is efficient, avoids redundancy, and maintains data integrity.

�What is Normalization?

Normalization is the process of organizing data in a database to:

 Reduce data redundancy


 Avoid data anomalies (insertion, update, deletion)
 Maintain data integrity
 Improve efficiency in storage and querying

�Normalization Steps Applied

Below are the steps taken to normalize the schema to Third Normal Form (3NF):

�1st Normal Form (1NF): Atomicity

Rule:
Each column should contain atomic (indivisible) values. No repeating groups or arrays.

Example Violation (Unnormalized):

diff
CopyEdit
OrderID | CustomerName | OrderedItems
------- | ------------ | ---------------------
101 | John Doe | Burger, Fries, Coke
Normalized to 1NF:

diff
CopyEdit
OrderID | CustomerName | OrderedItem
------- | ------------ | ------------
101 | John Doe | Burger
101 | John Doe | Fries
101 | John Doe | Coke

➡ Or better, separate Orders and OrderDetails tables.

�2nd Normal Form (2NF): Remove Partial Dependency

Rule:
All non-key attributes must depend on the entire primary key.

Example Violation:
In a table OrderDetails(OrderID, ItemID, ItemName, Quantity)
ItemName depends only on ItemID, not the full composite key.

Fix:

 Move ItemName to MenuItems


 Keep OrderDetails(OrderID, ItemID, Quantity)

�3rd Normal Form (3NF): Remove Transitive Dependency

Rule:
No non-key attribute should depend on another non-key attribute.

Example Violation:
In Users(UserID, Email, Password, RoleName)
RoleName is not dependent on UserID, but on a missing RoleID.

Fix:

 Create a separate Roles(RoleID, RoleName) table.


 Users will reference RoleID as a foreign key.
�Final Normalized Schema Overview (3NF)
Table Description

Users Stores user info (FK to Roles)

Roles Separate table for user roles

Restaurants Info about restaurants (FK to Users)

MenuItems Menu per restaurant (FK to Restaurants)

Orders Customer orders (FK to Users & Restaurants)

OrderDetails Items in each order (composite FK)

Payments Payment info per order

Reviews Ratings/comments (FK to Users & Restaurants)

�Summary of Benefits

 ✔ Minimal data duplication


 ✔ Better data consistency
 ✔ Easier schema maintenance
 ✔ Faster query performance
 ✔ Well-structured relationships

�Database Schema Definition

Project: Online Food Ordering System


Context: University Database Systems Project
Design Level: Normalized to 3NF

1. Users Table
sql
CREATE TABLE Users (
UserID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Email VARCHAR(100) UNIQUE NOT NULL,
PasswordHash VARCHAR(255) NOT NULL,
Phone VARCHAR(20),
RoleID INT,
FOREIGN KEY (RoleID) REFERENCES Roles(RoleID)
);

2. Roles Table
Sql

CREATE TABLE Roles (


RoleID INT PRIMARY KEY AUTO_INCREMENT,
RoleName VARCHAR(50) UNIQUE NOT NULL
);

3. Restaurants Table
sql

CREATE TABLE Restaurants (


RestaurantID INT PRIMARY KEY AUTO_INCREMENT,
OwnerID INT,
RestaurantName VARCHAR(100) NOT NULL,
Address TEXT NOT NULL,
Phone VARCHAR(20),
Status VARCHAR(20) DEFAULT 'Pending',
FOREIGN KEY (OwnerID) REFERENCES Users(UserID)
);

�4. MenuItems Table


sql
CopyEdit
CREATE TABLE MenuItems (
ItemID INT PRIMARY KEY AUTO_INCREMENT,
RestaurantID INT,
ItemName VARCHAR(100) NOT NULL,
Description TEXT,
Price DECIMAL(10, 2) NOT NULL,
Category VARCHAR(50),
FOREIGN KEY (RestaurantID) REFERENCES Restaurants(RestaurantID)
);

5. Orders Table
sql

CREATE TABLE Orders (


OrderID INT PRIMARY KEY AUTO_INCREMENT,
CustomerID INT,
RestaurantID INT,
OrderDate DATETIME DEFAULT CURRENT_TIMESTAMP,
TotalAmount DECIMAL(10, 2),
Status VARCHAR(50) DEFAULT 'Placed',
FOREIGN KEY (CustomerID) REFERENCES Users(UserID),
FOREIGN KEY (RestaurantID) REFERENCES Restaurants(RestaurantID)
);

6. OrderDetails Table
sql

CREATE TABLE OrderDetails (


OrderDetailID INT PRIMARY KEY AUTO_INCREMENT,
OrderID INT,
ItemID INT,
Quantity INT NOT NULL,
Subtotal DECIMAL(10, 2),
FOREIGN KEY (OrderID) REFERENCES Orders(OrderID),
FOREIGN KEY (ItemID) REFERENCES MenuItems(ItemID)
);

7. Payments Table
sql

CREATE TABLE Payments (


PaymentID INT PRIMARY KEY AUTO_INCREMENT,
OrderID INT,
Amount DECIMAL(10, 2) NOT NULL,
PaymentMethod VARCHAR(50), -- e.g., 'COD', 'Online'
PaymentStatus VARCHAR(50),
PaymentDate DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (OrderID) REFERENCES Orders(OrderID)
);

8. Reviews Table
Sql

CREATE TABLE Reviews (


ReviewID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT,
RestaurantID INT,
Rating INT CHECK (Rating BETWEEN 1 AND 5),
Comment TEXT,
ReviewDate DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (RestaurantID) REFERENCES Restaurants(RestaurantID)
);

�Notes on Constraints

 All primary keys are auto-incrementing integers.


 All relationships are defined via foreign keys.
 Passwords are assumed to be stored as secure hashes.
 CHECK constraints ensure ratings are within valid bounds.
 Cascading (e.g., ON DELETE CASCADE) can be added for advanced control.

�Purpose of DBMS in Implementation

During implementation, a Database Management System is selected and configured to:

 Create the actual database schema


 Store, retrieve, and manage data efficiently
 Enforce constraints (primary/foreign keys, data types)
 Support transactions, security, and backups

�Selected DBMS: Example — MySQL (or PostgreSQL/SQLite)

�Why MySQL?

 Open-source and widely supported


 Easy integration with PHP, Python, and web frameworks
 User-friendly tools like phpMyAdmin
 Rich support for SQL, indexing, joins, triggers, and views

�Implementation Steps with DBMS

1. Install and Configure DBMS

 Install MySQL Server


 Use command-line or GUI tools like MySQL Workbench or phpMyAdmin
 Set up root/admin credentials
2. Create the Database

sql
CopyEdit
CREATE DATABASE OnlineFoodOrdering;
USE OnlineFoodOrdering;

3. Define Tables and Relationships

 Execute SQL scripts to create normalized tables (Users, Orders, MenuItems, etc.)
 Apply primary keys, foreign keys, CHECK constraints

4. Insert Sample Data

sql
CopyEdit
INSERT INTO Roles (RoleName) VALUES ('Customer'), ('Admin'), ('Restaurant');
INSERT INTO Users (Name, Email, PasswordHash, RoleID) VALUES (...);

5. Test CRUD Operations

 Ensure Insert, Update, Delete, and Read work properly across tables
 Use JOINs to combine data (e.g., Orders with MenuItems)

6. Implement Views and Stored Procedures (optional)

 Example: A view to display order summary per customer

sql
CopyEdit
CREATE VIEW CustomerOrderSummary AS
SELECT Users.Name, Orders.OrderID, Orders.TotalAmount
FROM Users
JOIN Orders ON Users.UserID = Orders.CustomerID;

7. Ensure Data Security

 Use hashed passwords (e.g., bcrypt on the backend)


 Limit access using user privileges

sql
CopyEdit
GRANT SELECT, INSERT ON OnlineFoodOrdering.* TO 'webappuser'@'localhost';

8. Backup and Recovery Setup

 Use mysqldump for backups


 Schedule periodic dumps for database safety
�Summary: DBMS Role in Implementation
Task Role of DBMS (MySQL)

Schema Creation Define and enforce structure

Data Storage and Retrieval Efficient, relational access to food/order data

Constraints and Integrity Enforce keys, types, validation rules

Security Role-based access control

Performance Optimization Use of indexes, queries, and views

Data Backup Ensure recovery from failures

Here’s a comprehensive Data Insertion section for the implementation step of your Online Food
Ordering Database Management System (OFODMS) project, suitable for a university-level database
systems course. It includes sample data sets used for testing and demonstration purposes.

�Data Insertion – Sample Datasets for Testing & Demonstration

Project: Online Food Ordering DBMS


Phase: Implementation
Context: University-Level Database Systems

�Purpose:


 Populate the database with realistic test data
 Validate relationships, constraints, and queries
 Demonstrate system functionality (CRUD, reports, etc.)

1. Roles Table
sql

INSERT INTO Roles (RoleName) VALUES


('Admin'),
('Customer'),
('Restaurant');

2. Users Table
sql

INSERT INTO Users (Name, Email, PasswordHash, Phone, RoleID) VALUES


('Alice Admin', '[email protected]', 'hashedpass1', '111-222-3333', 1),
('Bob Customer', '[email protected]', 'hashedpass2', '222-333-4444', 2),
('Charlie Chef', '[email protected]', 'hashedpass3', '333-444-5555', 3);

3. Restaurants Table
sql

INSERT INTO Restaurants (OwnerID, RestaurantName, Address, Phone, Status)


VALUES
(3, 'Charlie's Kitchen', '123 Main St', '333-444-5555', 'Approved');

4. MenuItems Table
sql

INSERT INTO MenuItems (RestaurantID, ItemName, Description, Price, Category)


VALUES
(1, 'Cheese Burger', 'Beef patty with cheese', 5.99, 'Main Course'),
(1, 'French Fries', 'Crispy potato fries', 2.99, 'Sides'),
(1, 'Soda', 'Coca-Cola 500ml', 1.50, 'Drinks');

5. Orders Table
sql

INSERT INTO Orders (CustomerID, RestaurantID, OrderDate, TotalAmount, Status)


VALUES
(2, 1, NOW(), 10.48, 'Placed');

6. OrderDetails Table
sql

INSERT INTO OrderDetails (OrderID, ItemID, Quantity, Subtotal) VALUES


(1, 1, 1, 5.99),
(1, 2, 1, 2.99),
(1, 3, 1, 1.50);

7. Payments Table
Sql

INSERT INTO Payments (OrderID, Amount, PaymentMethod, PaymentStatus,


PaymentDate) VALUES
(1, 10.48, 'Online', 'Paid', NOW());

8. Reviews Table
sql

INSERT INTO Reviews (UserID, RestaurantID, Rating, Comment, ReviewDate)


VALUES
(2, 1, 5, 'Delicious food and fast delivery!', NOW());

�Use Cases Enabled by Sample Data:

 Query order summaries


 Join user and restaurant reviews
 Generate menu listings
 Simulate payment flows and history
 Test relational integrity (foreign keys)

�SQL Queries for Data Manipulation (DML)

Project: Online Food Ordering DBMS


Phase: Implementation
Focus: SELECT, INSERT, UPDATE, DELETE

�1. SELECT Statements (Retrieving Data)

a) List all menu items from a restaurant

sql
CopyEdit
SELECT ItemID, ItemName, Price, Category
FROM MenuItems
WHERE RestaurantID = 1;
b) Display order history for a specific customer

sql
CopyEdit
SELECT Orders.OrderID, Orders.OrderDate, Orders.TotalAmount, Orders.Status
FROM Orders
JOIN Users ON Orders.CustomerID = Users.UserID
WHERE Users.Email = '[email protected]';

c) Show detailed items in a specific order

sql
CopyEdit
SELECT MenuItems.ItemName, OrderDetails.Quantity, OrderDetails.Subtotal
FROM OrderDetails
JOIN MenuItems ON OrderDetails.ItemID = MenuItems.ItemID
WHERE OrderDetails.OrderID = 1;

d) Get average rating per restaurant

sql
CopyEdit
SELECT Restaurants.RestaurantName, AVG(Reviews.Rating) AS AverageRating
FROM Reviews
JOIN Restaurants ON Reviews.RestaurantID = Restaurants.RestaurantID
GROUP BY Restaurants.RestaurantName;

�2. INSERT Statements (Adding Data)

a) Add a new customer user

sql
CopyEdit
INSERT INTO Users (Name, Email, PasswordHash, Phone, RoleID)
VALUES ('Emily Eats', '[email protected]', 'hashedpassword', '999-888-7777',
2);

b) Add a new menu item

sql
CopyEdit
INSERT INTO MenuItems (RestaurantID, ItemName, Description, Price, Category)
VALUES (1, 'Veggie Wrap', 'Fresh vegetables in a tortilla wrap', 4.99, 'Main
Course');

c) Place a new order and items

sql
CopyEdit
-- Insert Order
INSERT INTO Orders (CustomerID, RestaurantID, OrderDate, TotalAmount, Status)
VALUES (2, 1, NOW(), 9.98, 'Placed');

-- Insert Order Details


INSERT INTO OrderDetails (OrderID, ItemID, Quantity, Subtotal)
VALUES (2, 1, 1, 5.99),
(2, 3, 1, 3.99);

�3. UPDATE Statements (Modifying Data)

a) Update the status of an order

sql
CopyEdit
UPDATE Orders
SET Status = 'Delivered'
WHERE OrderID = 1;

b) Modify the price of a menu item

sql
CopyEdit
UPDATE MenuItems
SET Price = 6.99
WHERE ItemName = 'Cheese Burger' AND RestaurantID = 1;

�4. DELETE Statements (Removing Data)

a) Delete a customer account

sql
CopyEdit
DELETE FROM Users
WHERE Email = '[email protected]' AND RoleID = 2;

b) Remove a menu item

sql
CopyEdit
DELETE FROM MenuItems
WHERE ItemID = 4 AND RestaurantID = 1;

�Use in Implementation Phase

These DML statements are used in:

 Application back-end development (form submissions)


 Manual testing of database integrity
 Validating front-end and back-end connectivity
 Demonstrating CRUD operations in university presentations or demos

�Stored Procedures & Functions

Phase: Implementation
Context: University-Level DBMS Project
DBMS: MySQL (compatible with PostgreSQL/SQL Server with slight syntax changes)

�1. Stored Procedure: Place an Order

Handles order creation and item insertion into OrderDetails.

sql
CopyEdit
DELIMITER $$

CREATE PROCEDURE PlaceOrder (


IN p_CustomerID INT,
IN p_RestaurantID INT,
IN p_Item1ID INT,
IN p_Quantity1 INT,
IN p_Item2ID INT,
IN p_Quantity2 INT
)
BEGIN
DECLARE orderTotal DECIMAL(10,2);
DECLARE price1 DECIMAL(10,2);
DECLARE price2 DECIMAL(10,2);
DECLARE orderID INT;

-- Get item prices


SELECT Price INTO price1 FROM MenuItems WHERE ItemID = p_Item1ID;
SELECT Price INTO price2 FROM MenuItems WHERE ItemID = p_Item2ID;

-- Calculate total
SET orderTotal = (price1 * p_Quantity1) + (price2 * p_Quantity2);

-- Insert into Orders


INSERT INTO Orders (CustomerID, RestaurantID, OrderDate, TotalAmount,
Status)
VALUES (p_CustomerID, p_RestaurantID, NOW(), orderTotal, 'Placed');

SET orderID = LAST_INSERT_ID();

-- Insert into OrderDetails


INSERT INTO OrderDetails (OrderID, ItemID, Quantity, Subtotal)
VALUES
(orderID, p_Item1ID, p_Quantity1, price1 * p_Quantity1),
(orderID, p_Item2ID, p_Quantity2, price2 * p_Quantity2);
END$$

DELIMITER ;

�2. Stored Function: Get Average Rating of a Restaurant

Returns average review rating.

sql
CopyEdit
DELIMITER $$

CREATE FUNCTION GetAverageRating(RestaurantID INT)


RETURNS DECIMAL(3,2)
DETERMINISTIC
BEGIN
DECLARE avgRating DECIMAL(3,2);

SELECT AVG(Rating) INTO avgRating


FROM Reviews
WHERE Reviews.RestaurantID = RestaurantID;

RETURN IFNULL(avgRating, 0.00);


END$$

DELIMITER ;

�3. Stored Procedure: Register a New Customer

Simplifies customer registration process.

sql
CopyEdit
DELIMITER $$

CREATE PROCEDURE RegisterCustomer (


IN p_Name VARCHAR(100),
IN p_Email VARCHAR(100),
IN p_PasswordHash VARCHAR(255),
IN p_Phone VARCHAR(15)
)
BEGIN
INSERT INTO Users (Name, Email, PasswordHash, Phone, RoleID)
VALUES (p_Name, p_Email, p_PasswordHash, p_Phone, 2); -- RoleID 2 =
Customer
END$$

DELIMITER ;
�4. Stored Procedure: Update Order Status

Used by restaurant/admin to update order delivery status.

sql
CopyEdit
DELIMITER $$

CREATE PROCEDURE UpdateOrderStatus (


IN p_OrderID INT,
IN p_NewStatus VARCHAR(20)
)
BEGIN
UPDATE Orders
SET Status = p_NewStatus
WHERE OrderID = p_OrderID;
END$$

DELIMITER ;

�Benefits in Implementation
Procedure/Function Purpose

PlaceOrder() Encapsulates order creation logic

GetAverageRating() Enables dashboard/reporting of ratings

RegisterCustomer() Simplifies sign-up logic

UpdateOrderStatus() Modular update for order tracking

Would you like me to provide a .sql export of these procedures/functions or help you integrate them
into a front-end app?

You might also like