9 Allqueriescompleted 1 Indocument
9 Allqueriescompleted 1 Indocument
ABSTRACT…………….……………………..………………… i
CHAPTER 1. INTRODUCTION
1.1 Introduction to the topic…………………………………........ 1
1.2 Problem Statement……………………………………………. 1
1.3 Objectives…………………………………………………….. 2
CHAPTER 2. DATABASE DESIGN
2.1 List of Attributes, entities and relationship…………………… 3-7
2.2 E-R Diagram………………………………………………….. 8-8
CHAPTER 3. RELATIONAL MODEL
3.1 Database languages……………………………………………. 9-10
3.2 Table Description……………………………………………… 10-13
3.3 Relational Database Scheme………………………………….. 14-14
3.4 Relational Queries……………………………………………. 14-42
CHAPTER 4. CONCLUSION AND FUTUREWORK
4.1 Conclusion………………………………………………………. 43-43
4.2 Future Work…………………………………………………….. 44-44
ii
CHAPTER 1. INTRODUCTION
Online shopping databases play a critical role in simplifying the consumer journey by offering
comprehensive product catalogs. These catalogs contain a wide array of products, allowing users
to easily search, browse, and select items of interest. Detailed information, including descriptions,
specifications, pricing, and availability, enables informed decision-making, empowering
customers to make confident purchases. By providing a user-friendly interface and efficient
navigation tools, online shopping databases optimize the browsing experience, ensuring that
shoppers can find the desired products quickly and effortlessly.
In addition to facilitating product discovery, online shopping databases streamline the checkout
process, ensuring secure and hassle-free transactions. These databases integrate with secure
payment gateways, accommodating various payment methods while prioritizing the protection
of sensitive customer information. Robust security measures, such as encryption protocols and
adherence to industry standards, instill confidence in users, fostering trust and credibility.
Furthermore, online shopping databases often leverage customer data and browsing history to
offer personalized recommendations, enhancing the shopping experience and guiding customers
towards relevant products that align with their preferences.
Problem Statement
Despite the increasing popularity of online shopping, there are several challenges that need to
be addressed to optimize the online retail experience. The existing problem lies in the lack of
efficient and user-friendly online shopping databases that can provide comprehensive product
catalogs, streamlined checkout processes, and personalized recommendations. This leads to
frustration and inefficiency for consumers who struggle to find desired products, experience
insecure transactions, and lack personalized guidance during their online shopping journey.
Therefore, there is a pressing need to develop robust online shopping databases that can
effectively address these challenges and enhance the overall user experience.
1
Objective
i. Provide a Comprehensive Product Catalog: The primary objective of an online shopping database
is to offer a comprehensive and up-to-date product catalog. This involves organizing and
maintaining a vast array of products, including detailed information such as descriptions,
specifications, pricing, and availability. The database should enable efficient search, browsing, and
filtering functionalities to allow users to easily locate and explore the products they are interested
in.
ii. Ensure Secure and Seamless Checkout Processes: Another objective is to prioritize the security and
seamlessness of the checkout process. The online shopping database should integrate with secure
payment gateways, implementing robust encryption techniques to protect customer data during
transactions. It should provide multiple payment options to accommodate various user preferences,
ensuring a frictionless experience. Streamlining the checkout process will contribute to building
trust and confidence among users, encouraging them to complete their purchases.
iii. Personalize Recommendations: Online shopping databases should incorporate personalized
recommendation systems to enhance the user experience. By leveraging customer preferences,
browsing history, and behavior patterns, the database can generate tailored product
recommendations. This objective aims to guide users towards relevant products that align with their
interests, increasing the chances of discovering new items and improving overall customer
satisfaction.
iv. Implement Efficient Order Tracking and Inventory Management: An important objective is to
implement an efficient order tracking system that allows users to monitor the progress of their
purchases from placement to delivery. This provides transparency and reassurance to customers,
reducing uncertainty and enhancing the overall shopping experience. Additionally, the database
should automatically update stock levels and manage inventory to ensure accurate product
availability information, minimizing the risk of overselling or backordering.
v. Enhance User Satisfaction and Foster Customer Loyalty: Ultimately, the objective of an online
shopping database is to enhance user satisfaction and foster long-term customer loyalty. By
providing a seamless, secure, and personalized shopping experience, the database aims to create a
positive impression on users, encouraging them to return for future purchases and recommend the
platform to others. This objective focuses on building strong relationships with customers, driving
repeat business, and establishing a loyal customer base.
By addressing these objectives, online shopping databases can optimize the online shopping experience,
improve customer satisfaction, and contribute to the success of e-commerce platforms.
2
CHAPTER 2. DATABASE DESIGN
Attributes Type
Product_id int
Product_Name Varchar(40)
Description Varchar(40)
Price Money
Stock_Quantity Varchar(50)
Category_id int
Attributes Type
Category_id int
Category_name unique
Attributes Type
Cid int
CName Varchar(400)
Cage int
CMobile Varchar(10)
CEmail Varchar(300)
Attributes Type
Order_id int
Customer_id int
Order_date date
Total_amount int
3
5. Entity Name: Transactions
Attributes Type
Transaction_id int
Order_id int
Payment_date Date
Payment_Method Varchar(30)
Amount int
Attributes Type
Order_id int
Product_id Int
Quantity int
Price money
Attributes Type
Review id int
Customer_id int
Product_id int
Rating int
Comment Varchar(40)
Review_Date Date
Attributes Type
Customer_id int
C_address Varchar(50)
City Varchar(40)
4
9. Entity Name: Wishlist
Attributes Type
Wishlist_id int
Customer_id int
Product_id int
Wishlist_Date Date
Attributes Type
Cart_id int
Customer_id int
Product_id int
Cart_Date Date
Quantity int
Attributes Type
Promotion_id int
Promotion_Name Varchar(50)
Promotion_Start_Date Date
Promotion_End_Date Date
Discount_Percentage Varchar(25)
Attributes Type
Brand_id int
Brand_name Varchar(25)
5
2.1.1 Entities and their relationships:
The above diagram is a simple representation of entities which shows the connectivity
between all the entities and the relationship between various entities
To know in detail about the types of relationships that exist between all the entities and to
know the different attributes that describes about the entity we design ER(entity relation)
diagram.
6
2.2 E-R Diagram
7
CHAPTER 3. RELATIONAL MODEL
Database languages
Four categories of database languages :
1. Data definition language (DDL)
Data definition language (DDL) creates the framework of the database by specifying the
database schema, which is the structure that represents the organization of data. Its common
uses include the creation and alteration of tables, files, indexes and columns within the
database. This language also allows users to rename or drop the existingdatabase or its
components.
Here's a list of DDL statements:
• CREATE: Creates a new database or object, such as a table, index or column.
• ALTER: Changes the structure of the database or object.
• DROP: Deletes the database or existing objects.
• RENAME: Renames the database or existing objects.
8
4. Transaction control language (TCL)
Transaction control language (TCL) manages the transactions within a database.
Transactions group a set of related tasks into a single, executable task. All the tasks must
succeed in order for the transaction to work. Here's a list of TCL statements:
• COMMIT: Carries out a transaction.
• ROLLBACK: Restores a transaction if any tasks fail to execute.
Table Description
Following are the tables along with constraints used in All in one travel booking database.
Constraint: Primary Key: The primary key constraint is applied to the "Product_id"
column, ensuring that each product has a unique identifier within the table.
Foreign Key: The foreign key constraint is applied to the "Category_id" column,
referencing the "Category_id" column in the "categories" table. This constraint ensures that
the values in the "Category_id" column of the "Products" table must match the values in the
"Category_id" column of the "categories" table, maintaining the integrity of the relationship
between the two tables.
Constraint: Primary Key: The primary key constraint is applied to the "Category_id" column,
ensuring that each category has a unique identifier within the table.
9
Customers: Cid serves as the unique identifier for each customer in the table.Cname
stores the name of the customer, allowing up to 40 characters. Cage represents the age
of the customer.CMobile stores the mobile number of the customer, limited to 10
characters.CEmail contains the email address of the customer, allowing up to 300
characters.Caddress stores the address of the customer, allowing up to 300 characters.
Constraint: Primary Key: The primary key constraint is applied to the "Cid" column,
ensuring that each customer has a unique identifier within the table.
Orders: Order_id serves as the unique identifier for each order in the table.Customer_id
refers to the customer to whom the order belongs, linking to the "Cid" column in the
"Customers" table.Order_date represents the date when the order was
placed.Total_amount: integer - stores the total amount of the order.
Constraints: Primary Key the primary key constraint is applied to the "Order_id"
column, ensuring that each order has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "customer_id" column, referencing the "Cid"
column in the "Customers" table. This constraint ensures that the values in the
"customer_id" column of the "Orders" table must match the values in the "Cid"column
of the "Customers" table, maintaining the integrity of the relationship between the two
tables.
Constraints: Primary Key the primary key constraint is applied to the "Transaction_id"
column, ensuring that each transaction has a unique identifier within the table.Foreign
Key the foreign key constraint is applied to the "Order_id" column, referencing the
"Order_id" column in the "Orders" table. This constraint ensures that the values in the
"Order_id" column of the "Transactions" table must match the values in the "Order_id"
column of the "Orders" table, maintaining the integrity of therelationship between the
two tables.
10
OrderItems Table: Order_id refers to the order to which the item belongs, linking to
the "Order_id" column in the "Orders" table.Product_id refers to the product associated
with the item, linking to the "Product_id" column in the "Products1" table.Quantity
represents the quantity of the product ordered.Price stores the price of the product.
Constraints: Foreign Key the foreign key constraint is applied to the "Order_id"
column, referencing the "Order_id" column in the "Orders" table. This constraintensures
that the values in the "Order_id" column of the "OrderItemsTable" table must match the
values in the "Order_id" column of the "Orders" table, maintaining the integrity of the
relationship between the two tables.Foreign Key the foreign key constraint is applied to
the "Product_id" column, referencing the "Product_id" column in the "Products1" table.
This constraint ensures that the values in the "Product_id" column of the
"OrderItemsTable" table must match the values in the "Product_id" column of the
"Products1" table, maintaining the integrity of the relationship between the two table.
Reviews: Review_id serves as the unique identifier for each review in the
table.Customer_id refers to the customer who wrote the review, linking to the "Cid"
column in the "Customers1" table.Product_id refers to the product for which thereview
was written, linking to the "Product_id" column in the "Products1" table.Rating
represents the rating given in the review. The CHECK constraint ensures that the rating
can only be 0, 1, 2, 3, 4, or 5.Comment stores the comment or review content, limited
to 20 characters.Review_date represents the date when the review was posted.
Constraints: Primary Key the primary key constraint is applied to the "review_id"
column, ensuring that each review has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the "Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Reviews" table must match the values in the "Cid"
column of the "Customers1" table, maintaining the integrity of the relationship between
the two tables.
11
Addressess: Customer_id refers to the customer to whom the address belongs, linking
to the "Cid" column in the "Customers1" table.C_Address stores the address of the
customer, limited to 50 characters.City stores the city associated with the address,
limited to 40 characters.
Constraints: Foreign Key the foreign key constraint is applied to the "Customer_id"
column, referencing the "Cid" column in the "Customers1" table. This constraintensures
that the values in the "Customer_id" column of the "Addressess" table must match the
values in the "Cid" column of the "Customers1" table, maintaining the integrity of the
relationship between the two tables.
Wishlist: Wishlist_id serves as the unique identifier for each wishlist in the
table.Customer_id refers to the customer who owns the wishlist, linking to the "Cid"
column in the "Customers1" table.Product_id refers to the product added to the wishlist,
linking to the "Product_id" column in the "Products1" table. Wishlist_Date represents
the date when the product was added to the wishlist.
Constraints: Primary Key the primary key constraint is applied to the "Wishlist_id"
column, ensuring that each wishlist has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the"Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Wishlist" table must match the values in the "Cid"
column of the "Customers1" table, maintaining the integrity of the relationship between
the two tables.Foreign Key the foreign key constraint is applied to the "Product_id"
column, referencing the "Product_id" column in the "Products1" table. This constraint
ensures that the values in the "Product_id" column of the "Wishlist" table must match
the values in the "Product_id" column of the "Products1" table, maintaining the integrity
of the relationship between the two tables.
12
Cart: Cart_item_id serves as the unique identifier for each item in the cart.Customer_id
refers to the customer who owns the cart, linking to the "Cid" column in the
"Customers1" table.Product_id refers to the product added to the cart, linking to the
"Product_id" column in the "Products1" table.Cart_date represents the date when the
product was added to the cart.Quantity stores the quantity of the productadded to the
cart.
Constraints: Primary Key the primary key constraint is applied to the "cart_item_id"
column, ensuring that each cart item has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the"Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Cart" table must match the values in the "Cid" column
of the "Customers1" table, maintaining the integrity of the relationship between the
two tables.Foreign Key the foreign key constraint is applied to the "Product_id"column,
referencing the "Product_id" column in the "Products1" table. This constraint ensures
that the values in the "Product_id" column of the "Cart" table must match the values in
the "Product_id" column of the "Products1" table, maintaining the integrity
Promotions: Promotion_id serves as the unique identifier for each promotion in the
table.Promotion_Name stores the name or title of the promotion, allowing up to 50
characters.Promotion_Start_date represents the start date of the
promotion.Promotion_End_date represents the end date of the
promotion.discount_percentage stores the percentage of discount offered by the
promotion.
Constraints: Primary Key: The primary key constraint is applied to the "Promotion_id"
column, ensuring that each promotion has a unique identifier within the table.
13
Brands: Brand_id serves as the unique identifier for each brand in the table.
Brand_name stores the name of the brand, allowing up to 20 characters.
Constraints: Primary Key the primary key constraint is applied to the "Brand_id"
column, ensuring that each brand has a unique identifier within the table.
Discount: Discount_id serves as the unique identifier for each discount in the
table.Discount_code stores the discount code for each discount, limited to 20 characters.
The UNIQUE constraint ensures that each discount code is unique within the
table.Start_date represents the start date of the discount.End_date represents theend
date of the discount.Discount_percentage stores the percentage of the discount offered.
The decimal data type with precision 5 and scale 2 allows for values with upto 5 digits,
2 of which are reserved for decimal places.
Constraints: Primary Key the primary key constraint is applied to the "Discount_id"
column, ensuring that each discount has a unique identifier within the table.Unique
Constraint the unique constraint is applied to the "Discount_code" column, ensuring that
each discount code is unique within the table.
14
15
16
17
Relational Database Scheme
The relational database schema for Cricket World Cup database is as follows:
1. Products (Product_id,Product_Name,Description,Price,Stock_Quantity,Category_id)
2. Categories (Category_id,Category_Name)
3. Customers (Cid,CNmae,Cage,CMobile,CEmail,CAddress)
4. Orders (Order_id,Customer_id,Order_date,Total_amount)
5. Transactions (Transaction_id,Order_id,Payment_date, Payment_method,Amount)
6. Order Items Table (Order_id,Product_id,Quantity,Price)
7. Reviews (Review_id,Customer_id,Product_id,Rating,Comment,Review_date)
8. Addressess (Customer_id,C_Address,City)
9. Wishlist (Wishlist_id,Customer_id,Product_id,Wishlist_date)
10. Cart (Cart_item_id,Customer_id,Product_id,Cart_date,Quantity)
11. Brands (Brand_id,Brand_Name)
12. Discount (Discount_id,Discount_code,Start_date,End_date,Discount_percentage)
18
Relational Queries
/* create a table Products*/
Create table Products
(
Product_id int primary key,
product_name Varchar(40),
Description Varchar(40),
price money,
stock_quantity Varchar(50),
Category_id int Foreign key references categories(Category_id),
);
INSERT INTO Products(Product_id, Product_name, Description, Price, stock_quantity,
Category_id)
VALUES(1, 'iPhone 12', 'Apple smartphone', 999.99, 10, 1);
INSERT INTO Products (Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(2, 'Samsung Galaxy S21', 'Android smartphone', 899.99, 15, 1);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(3, 'Nike Air Max', 'Running shoes', 129.99, 20, 2);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(4, 'Adidas Ultraboost', 'Running shoes', 149.99, 30, 2);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(5, 'Instant Pot', 'Multi-cooker', 79.99, 5, 3);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(6, 'Cookware Set', 'Stainless steel pots and pans', 199.99, 8, 3);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(7, 'Harry Potter and the Sorcerer Stone', 'Fantasy novel', 12.99, 50, 4);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(8, 'The Great Gatsby', 'Classic novel', 9.99, 40, 4);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(9, 'Loreal Paris Mascara', 'Volumizing mascara', 8.99, 25, 5);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(10, 'NIVEA Men Shaving Cream', 'For sensitive skin', 4.99, 30, 5);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(11, 'Yoga Mat', 'Non-slip exercise mat', 19.99, 12, 6);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(12, 'Dumbbell Set', 'Weights for strength training', 49.99, 7, 6);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(13, 'LEGO Star Wars Set', 'Building blocks', 59.99, 18, 7);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(14, 'Board Game: Monopoly', 'Classic family game', 29.99, 25, 7);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(15, 'Car Jump Starter', 'Portable power bank', 79.99, 10, 8);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(16, 'Car Floor Mats', 'All-weather mats', 39.99, 15, 8);
19
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(17, 'Vitamin C Supplement', 'Immune support', 9.99, 40, 9);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(18, 'Fitness Tracker', 'Activity monitor', 49.99, 20, 9);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(19, 'Sofa', '3-seater couch', 599.99, 3, 10);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(20, 'Dining Table', 'Wooden table with chairs', 399.99, 5, 10);
select *from Products;
Output:
20
/*create a table Categories*/
Create table Categories
(
Category_id int primary key,
Category_name Varchar(40),
);
INSERT INTO Categories (Category_id, Category_name)
VALUES(1, 'Electronics');
INSERT INTO Categories (Category_id, Category_name)
VALUES(2, 'Clothing');
INSERT INTO Categories (Category_id, Category_name)
VALUES(3, 'Home & Kitchen');
INSERT INTO Categories (Category_id, Category_name)
VALUES(4, 'Books');
INSERT INTO Categories (Category_id, Category_name)
VALUES(5, 'Beauty & Personal Care');
INSERT INTO Categories (Category_id, Category_name)
VALUES(6, 'Sports & Fitness');
INSERT INTO Categories (Category_id, Category_name)
VALUES(7, 'Toys & Games');
INSERT INTO Categories (Category_id, Category_name)
VALUES(8, 'Automotive');
INSERT INTO Categories (Category_id, Category_name)
VALUES(9, 'Health & Wellness');
INSERT INTO Categories (Category_id, Category_name)
VALUES(10, 'Furniture');
Output:
21
/*create a table Customers*/
23
Output
24
/*create a table Transactions*/
Create Table Transactions2
(
Transaction_id int Primary Key,
Order_id int Foreign Key References Orders2(Order_id),
Payment_date date,
payment_method varchar(30),
Amount int,
);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(1, 1, '2023-05-01', 'Credit Card', 50);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(2, 12, '2023-05-02', 'PayPal', 75);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(3, 3, '2023-05-03', 'Credit Card', 100);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(4, 14, '2023-05-04', 'Google Pay', 20);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(5, 15, '2023-05-05', 'Credit Card', 150);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(6, 16, '2023-05-06', 'Credit Card', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(7, 17, '2023-05-07', 'PayPal', 90);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(8, 18, '2023-05-08', 'Credit Card', 80);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(9, 9, '2023-05-09', 'Google Pay', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(10, 10, '2023-05-10', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(11, 10, '2023-05-11', 'PayPal', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(12, 12, '2023-05-12', 'Credit Card', 30);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(13, 13, '2023-05-13', 'Google Pay', 110);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(14, 14, '2023-05-14', 'Credit Card', 65);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(15, 15, '2023-05-15', 'Credit Card', 95);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(16, 16, '2023-05-16', 'PayPal', 55);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(17, 19, '2023-05-17', 'Credit Card', 85);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(18, 18, '2023-05-18', 'Google Pay', 25);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(9, 1019, '2023-05-19', 'Credit Card', 135);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(20, 21, '2023-05-20', 'PayPal', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(21, 20, '2023-05-21', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(22, 25, '2023-05-22', 'Google Pay', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(23, 22, '2023-05-23', 'Credit Card', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(24, 23, '2023-05-24', 'Credit Card', 150);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(25, 24, '2023-05-25', 'PayPal', 90);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(26, 22, '2023-05-26', 'Credit Card', 80);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(27, 28, '2023-05-27', 'Google Pay', 20);
25
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(28, 24, '2023-05-28', 'Credit Card', 100);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(29, 19, '2023-05-29', 'Credit Card', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(30, 10, '2023-05-30', 'PayPal', 110);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(31, 19, '2023-05-31', 'Credit Card', 65);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(32, 12, '2023-06-01', 'Google Pay', 95);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(33, 13, '2023-06-02', 'Credit Card', 55);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(34, 14, '2023-06-03', 'Credit Card', 85);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(35, 15, '2023-06-04', 'PayPal', 25);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(36, 16, '2023-06-05', 'Credit Card', 135);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(37, 19, '2023-06-06', 'Google Pay', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(38, 20, '2023-06-07', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(39, 21, '2023-06-08', 'Credit Card', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(40, 29, '2023-06-09', 'PayPal', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(41, 18, '2023-06-09', 'Paytm', 90);
Insert Into Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
Values(42, 19, '2023-05-09', 'Debit Card', 100);
Insert Into Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
Values(43, 20, '2023-08-08', 'Debit Card', 100);
26
Output
27
/*create a table Orders2 */
28
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(23, 23, '2023-01-23', 120);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(24, 24, '2023-01-24', 85);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(25, 25, '2023-01-25', 50);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(26, 16, '2023-01-26', 75);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(27, 27, '2023-01-27', 60);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(28, 28, '2023-01-28', 90);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(29, 29, '2023-01-29', 100);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(30, 30, '2023-01-30', 80);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(31, 31, '2023-01-31', 70);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(32, 13, '2023-02-01', 55);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(33, 23, '2023-02-02', 65);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(34, 34, '2023-02-03', 95);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(35, 35, '2023-02-04', 120);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(36, 13, '2023-02-05', 85);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(37, 17, '2023-02-06', 50);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(38, 8, '2023-02-07', 75);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(39, 9, '2023-02-08', 60);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(40, 40, ‘2023-02-09’,90);
29
Output
30
/* create a table Order Items Table2*/
31
Output
32
/* create a table Reviews2*/
Create Table Reviews2
(
review_id int Primary Key,
Customer_id int Foreign Key References Customers(Cid),
Product_id int Foreign Key References Products(Product_id),
rating int check(rating = 0 or rating = 1 or rating = 2 or rating = 3 or rating = 4 or
rating = 5),
Comment Varchar(20),
Review_date date,
);
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (1, 10, 4, 4, 'Great product!', '2023-05-01');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (2, 2, 4, 5, 'Excellent service!', '2023-05-03');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (3, 1, 4, 3, 'Average quality.', '2023-05-05');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (4, 35, 4, 2, 'Not satisfied.', '2023-05-07');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (5, 19, 4, 5, 'Highly recommended!', '2023-05-10');
Output
33
/*create a table Addressess2 */
Create Table Addressess2
(
Customer_id int Foreign Key References Customers(Cid),
C_Address Varchar(50),
City Varchar(40)
);
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (1, '123 Main St', 'New York');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (10, '456 Elm St', 'Los Angeles');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (13, '789 Oak St', 'Chicago');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (19, '321 Pine St', 'San Francisco');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (30, '654 Cedar St', 'Miami');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(14, '321 Cedar Ln', 'Miami');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(15, '876 Walnut St', 'Boston');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(16, '543 Spruce Dr', 'Seattle');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(17, '210 Birch Ave', 'Denver');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(18, '135 Oak St', 'Dallas');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(21, '468 Pine Rd', 'San Diego');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(28, '975 Cedar Ln', 'Atlanta');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(29, '246 Elm St', 'Phoenix');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(23, '864 Maple Ave', 'Philadelphia');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(25, '369 Walnut St', 'Las Vegas');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(27, '582 Spruce Dr', 'Austin');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(30, '123 Birch Ave', 'Nashville');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(31, '456 Oak St', 'Portland');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(32,’789 Pine Rd’,’Charlotte’);
34
Output
35
/*create a table Wishlist2 */
Output
36
/*create a table Cart2 */
Output
37
/* Create table Promotions2 */
Output
38
/*create a table Brands2 */
39
Output
Brand_id Brand_Name
1 Nike
2 Adidas
3 Puma
4 Reebok
5 Under Armour
6 New Balance
7 Vans
8 Converse
9 Fila
10 Skechers
11 Lacoste
12 Timberland
13 ASICS
14 Crocs
15 Balenciaga
16 Gucci
17 Prada
18 Versace
19 Calvin Klein
20 Tommy Hilfiger
40
SQL Queries
SELECT
p.*,c.Category_name
FROM Products p
JOIN Categories c
ON p.Category_id = c.Category_id;
output:
41
Query2: Give complete information of Customers with Order_id , Payment_Date and Order_Amount
Output:
43
Query3: Find the name of the customer with total amount he had payed
Output
CName TotalAmount
Abigail Davis 195
Amelia Johnson 150
Ava Smith 290
Benjamin Thomas 165
Charlotte Wilson 170
Ethan Taylor 120
Evelyn Johnson 280
Harper Martinez 130
Jackson Smith 40
Jacob Smith 90
James Martinez 40
John Smith 50
Liam Wilson 390
Logan Davis 190
Mia Davis 200
Michael Brown 100
Oliver Thomas 60
Sofia Anderson 340
Abigail Davis 195
Amelia Johnson 150
Ava Smith 290
Benjamin Thomas 165
Charlotte Wilson 170
Ethan Taylor 120
44
Query4: Find the id of the customer along with total amount he had payed
Output:
Cid TotalAmount
1 50
3 100
9 40
10 290
12 200
13 165
14 170
16 260
17 90
18 195
19 390
20 340
21 130
22 120
23 150
24 190
25 60
28 20
29 40
45
Query 5: Find the details of Products which are having price greater than 100
SELECT * FROM
Products
WHERE Price > 100;
Output
Query 6: Find the details of customers whose address is “321 Pine st”
output
output
Query 8: Find the id of Customer with the number of times customer ordered who has ordered more than one
Time
Output
Cid Number_of_times_Ordered
8 2
9 2
11 2
12 2
13 3
17 2
23 2
24 2
27 2
29 6
30 2
47
48
Query 9: Find the customer id and order date of the customers
Output
Cid Order_Date
29 2023-05-01
29 2023-05-03
29 2023-05-05
29 2023-05-08
29 2023-05-10
30 2023-03-11
17 2023-01-07
18 2023-01-08
9 2023-01-09
11 2023-01-10
11 2023-01-11
12 2023-01-12
13 2023-01-13
24 2023-01-25
26 2023-01-26
27 2023-01-27
8 2023-01-28
19 2023-01-29
12 2023-01-30
21 2023-01-31
22 2023-02-01
23 2023-02-02
24 2023-02-03
25 2023-02-04
16 2023-02-05
27 2023-02-06
28 2023-02-07
29 2023-02-08
30 2023-02-09
31 2023-01-25
13 2023-01-26
23 2023-01-27
34 2023-01-28
35 2023-01-29
13 2023-01-30
23 2023-01-31
34 2023-02-01
35 2023-02-02
13 2023-02-03
17 2023-02-04
8 2023-02-05
9 2023-02-06
40 2023-02-07
49
Query 10: Find Cid and CMobile from Customers who ordered any item
Output
Cid CMobile
8 6667778888
9 4445556666
11 8889990000
12 7778889999
13 2223334444
16 1112223333
17 8889990000
18 7778889999
19 2223334444
21 4445556666
22 1234567890
23 8889990000
24 7778889999
25 2223334444
26 6667778888
27 5556667777
28 4445556666
29 1234567890
30 8889990000
31 7778889999
34 5556667777
35 4445556666
40 5556667777
50
Query 11: Find Cid and CMobile from Customers who ordered any item and sort
the customer id in descending order
Output
Cid CMobile
40 5556667777
35 4445556666
34 5556667777
31 7778889999
30 8889990000
29 1234567890
28 4445556666
27 5556667777
26 6667778888
25 2223334444
24 7778889999
23 8889990000
22 1234567890
21 4445556666
19 2223334444
18 7778889999
17 8889990000
16 1112223333
13 2223334444
12 7778889999
11 8889990000
9 4445556666
8 6667778888
51
Query 12: Find the customer id and total number of orders by that customer
Output
Cid Number_of_items_Ordered
29 6
13 3
27 2
23 2
24 2
8 2
9 2
11 2
12 2
17 2
30 2
31 1
34 1
35 1
40 1
18 1
19 1
21 1
22 1
25 1
26 1
28 1
16 1
52
Query 13: Find the details of customers who has done the trabsaction by Credit card
technique
Output
53
Query 14: Find number of users using different methods for transaction of money
Output
Payment_Method Number_of_Users
Credit Card 20
Debit Card 2
Google Pay 8
PayPal 8
Paytm 1
Query 15: Find the customer name who has ordered any one item by using correlated subquery
CName
Sophia Anderson
James Martinez
Logan Thompson
Mia Davis
Benjamin Thomas
Evelyn Johnson
Jacob Smith
Abigail Davis
Liam Wilson
Harper Martinez
Ethan Taylor
Amelia Johnson
Logan Davis
Oliver Thomas
Mia Wilson
Lucas Brown
Evelyn Johnson
Jackson Smith
Ava Davis
Aiden Anderson
Scarlett Brown
Sebastian Thomas
Victoria Martinez
54
Query 16: Find the customer name and Customer id who has ordered any one item
by using correlated sub query
Output
Cid CName
1 John Smith
2 Emily Johnson
3 Michael Brown
4 Emma Davis
5 Daniel Wilson
6 Olivia Taylor
7 William Johnson
8 Sophia Anderson
9 James Martinez
10 Ava Smith
11 Logan Thompson
12 Mia Davis
13 Benjamin Thomas
14 Charlotte Wilson
15 Henry Brown
16 Evelyn Johnson
17 Jacob Smith
18 Abigail Davis
19 Liam Wilson
20 Sofia Anderson
21 Harper Martinez
22 Ethan Taylor
23 Amelia Johnson
24 Logan Davis
25 Oliver Thomas
26 Mia Wilson
27 Lucas Brown
28 Evelyn Johnson
29 Jackson Smith
30 Ava Davis
31 Aiden Anderson
32 Ella Martinez
33 Carter Wilson
34 Scarlett Brown
35 Sebastian Thomas
36 Luna Johnson
37 Grayson Davis
38 Penelope Wilson
39 Mateo Anderson
40 Victoria Martinez
41 Virat
55
Query 17: Find count of all customers ordered in the same date
Output
Number_of_persons_Ordered Order_Date
1 2023-01-07
1 2023-01-08
1 2023-01-09
1 2023-01-10
1 2023-01-11
1 2023-01-12
1 2023-01-13
1 2023-01-14
1 2023-01-16
1 2023-01-17
1 2023-01-18
1 2023-01-19
1 2023-01-20
1 2023-01-21
1 2023-01-22
1 2023-01-23
1 2023-01-24
1 2023-01-25
1 2023-01-26
1 2023-01-27
1 2023-01-28
1 2023-01-29
1 2023-01-30
1 2023-01-31
1 2023-02-01
1 2023-02-02
1 2023-02-03
1 2023-02-04
1 2023-02-05
1 2023-02-06
1 2023-02-07
1 2023-02-08
1 2023-02-09
1 2023-03-11
1 2023-05-01
1 2023-05-03
1 2023-05-05
1 2023-05-08
1 2023-05-10
56
Query 18: Find the details of transactions if it is present in the orders
Output
57
Query 19: Find the details of orders with product name for Order_id is 1
Output
Query 20: Find the details of customers who has done the transaction between '2023-05-01'
and '2023-05-31'
Output
58
Query 21: Find the details of customers who has ordered product id 4
Output
Query 22: Find the details of products with category name and sort the price in
descending order
Output
59
Query 23: Find all the customer id whose transaction amount is greater than 100
Output
Cid TotalAmount
10 290
12 200
13 165
14 170
16 260
18 195
19 390
20 340
21 130
22 120
23 150
24 190
Query 24: Find all the details of products whose stock quantity is less than 10
Output
60
Query 25: Find the Customer id and total amount he had done transaction through
PayPal and only display if total amount is greater than 50
Output
Query 26: Find the Customer id and total amount he had done transaction through Google
Pay and only display for total amount is greater than 50
Output
Cid Total Amount
12 95
13 110
19 70
25 60
61
Query 27: Find the Products along with category name which are in category
SELECT P.*,
C.Category_name FROM
Products P
JOIN Categories C ON P.Category_id = C.Category_id;
Output
62
Query 28: Find all product id and product name for category Clothing
Output
P_id P_Name
3 Nike Air Max
4 Adidas Ultraboost
Query 29: Create a view which contains category name and revenue of that items
Output
Category_Name TotalRevenue
Automotive 159.97
Beauty & Personal Care 17.98
Clothing 1349.91
Furniture 1399.97
Health & Wellness 249.95
Sports & Fitness 59.97
Toys & Games 29.99
63
Query 30: Create a view which contains id,name and total transaction amount of customers
Output
64
Query 31: Create a view which contains customer name with Order id , Quantity , and
Product Name
Output
65
Query 32: Find the customer name who had ordered any item by using Correlated subquery
SELECT C.CName
FROM
Customers asC
WHERE EXISTS
(
SELECT 1
FROM Orders2 O
WHERE O.customer_id = C.Cid
);
Output
CName
Sophia Anderson
James Martinez
Logan Thompson
Mia Davis
Benjamin Thomas
Evelyn Johnson
Jacob Smith
Abigail Davis
Liam Wilson
Harper Martinez
Ethan Taylor
Amelia Johnson
Logan Davis
Oliver Thomas
Mia Wilson
Lucas Brown
Evelyn Johnson
Jackson Smith
Ava Davis
Aiden Anderson
Scarlett Brown
Sebastian Thomas
Victoria Martinez
66
Query 33: Create a view which contains payment details with customer id
Output
67
Query 34: Find the details of Orders which are done transactions
select * from
Orders2 O
where exists (
select Order_id from
Transactions2 T
where O.Order_id =T.Order_id
);
Output
68
Query 35:Create a view which contains customer id in table Orders
Output
Cid
8
9
11
12
13
16
17
18
19
21
22
23
24
25
26
27
28
29
30
31
34
35
40
69
Query 36: Find the details of customers and transaction date of that customer
Output
Output
71
Query 38: Find the details of customers who has placed items in Orders
Output
72
Query 39: Find the Order details whose customer address is 1212 Elm st
Output
73
Query 40: Find Order_id,Payment_date, and Amount from transactions using correlated
sub query
select Order_id,Payment_date,Amount
from Transactions2
where Exists (
select Order_id from Orders2);
Output
74
Query 41: Find the item_id,discount_amount,validity_start_date and validity_end_date
for the category id less than or equal to 5
Output
Query 42: Find the Product Name and Product Description for validate start
date is 2023-06-01
Output
P_Name P_Description
iPhone 12 Apple smartphone
75
Query 43: Find the discount percentage for flash deal promotion
Output
Discount_Percentage
20
Output
no_of_itemsdiscounts_on_same_date validity_start_date
7 2023-06-01
7 2023-06-15
6 2023-07-01
Output
Promotion_Name Discount_Amount
Summer Sale 10
Summer Sale 20
Summer Sale 15
Summer Sale 9
Summer Sale 11.75
Summer Sale 19.5
Summer Sale 9
76
Query 46: Find the Name of the brand for Brand id is 10
Output
Brand_name
Skechers
Query 47: Find Brand id and Product Name whose price is greater than 100
Output
Brand_id Product_Name
1 iPhone 12
2 Samsung Galaxy S21
3 Nike Air Max
4 Adidas Ultraboost
6 Cookware Set
19 Sofa
20 Dining Table
id is 18
Output
Product_id Price
15 8.99
Query 49: Find the id and name of the customers whose mobile is not kept
in the database
Cmobile Isnull;
Output
Cid CName
41 Virat
77
Query 50: Create a view which contains rating is equal or greater than four
create view
All_Good_Rating_Members AS
select * from
Reviews2
where rating >= 4;
select * from All_Good_Rating_Members;
Output
78
SQL QUERIES:
Query1: Find the second most country, points
select COUNTRY,POINTS from POINTSTABLE where POINTS=
(
select max(POINTS)from POINTSTABLE where POINTS<>
(
select max(POINTS)from POINTSTABLE
)
)
/*output:
M_id M_name DID M_gender M_Address M_Mobile HID
601 shriya 1 F tirupathi 9998886661 101
602 keishna 2 M chennai 9998886662 102
603 meera 3 F kerala 9998886663 103
604 tarun 4 M chennai 9998886664 104
605 jansi 5 F tirupathi 9998886665 105
606 rupa 5 F tirupathi 9998886666 106
79
607 divya 1 F mumbai 9998886667 107
608 pradeepthi 2 F hyderabad 9998886668 108
609 reshma 3 F vijayawada 9998886669 109
610 deepak 4 M kerala 9998886610 110
611 raj 5 M chennai 9998886611 111
612 padma 1 F Bhopal 9998886612 112
613 karthik 2 M vizag 9998886613 113
614 neha 3 F vijayawada 9998886614 114
615 yeshwanth 4 M bangalore 9998886615 115
*/
Query2: Insert a coloumn name called Blood group with data type of varchar (10) and
constrain as null in customer table,manager table and staff table.
alter table customer add BloodGroup varchar (10) null
alter table manager add BloodGroup varchar (10) null
alter table staff add BloodGroup varchar (10) null
/*output:
s_sid s_name DID s_mobile BloodGroup
501 vicky 1 8889997771 NULL
502 ram 2 8889997772 NULL
503 kiran 3 8889997773 NULL
504 sunny 4 8889997774 NULL
505 vijay 5 8889997775 NULL
506 mahi 1 8889997776 NULL
CID CName Cmobile age crating BloodGroup
401 hima 9997776661 18 7 NULL
402 harshitha 9997776662 19 7 NULL
403 janu 9997776663 20 7 NULL
404 poojitha 9997776664 18 6 NULL
405 sreekar 9997776665 21 8 NULL
M_id M_name DID M_gender M_Addres M_Mobile HID
BloodGroup
601 shriya 1 F tirupathi 9998886661 101 NULL
80
60 keishna 2 M chennai 9998886662 102 NULL
603 meera 3 F kerala 9998886663 103 NULL
60 tarun 4 M chennai 9998886664 104 NULL
605 jansi 5 F tirupathi 9998886665 105 NULL
606 rupa 5 F tirupathi 9998886666 106 NULL
*/
Query3: Display the total cost of all facities which are avilable.
selectsum(F_cost)fromFacilities_available
/*output
(Nocolumnname)
21200.00 */
Query4:Display the details of customer who has given rating more than 7.
select * from customer where crating>7
/* output:
CName Cmobile age crating CID BloodGroup
sreekar 9997776665 21 8 405 NULL
rithu 9997776666 30 9 406 NULL
abhi 9997776667 40 10 407 NULL
rohan 9997776668 37 10 408 NULL
priya 9997776612 88 8 412 NULL
nitya 9997776613 78 10 413 NULL
jayanth 9997776614 68 9 414 NULL
rujith 9997776615 70 9 415 NULL */
Query5: Create view as hotel_manager whose address is tirupathi and update view
and drop the view.
create view hotel_manager from Manager as
select M_id, M_name, M_gender
from Manager where address='tirupathi'
select * from hotel_manager
/* output:
M_id M_name M_gender
81
601 shriya F
605 jansi F
606 rupa F
Query6: Find the total no:of customers whose age is greater than 60 and rating=9
select count(CID) from customer where age>60 and crating=9
/* output:
(No column name)
2 */
Query7: Find the ID's of customer whose contact is null.
select CID from customer where contact=null.
/* output:
CID
*/
Query8: Find the age and names of customers whose name begin and ends with p
and a and having atleast three characters.
select c.CName, c.age from customers c where CName like 'p_%a'
/* output:
CName age
Poojitha 18
priya 88 */
Query9: Find the ID's and names of customers who have given rating more than 8.
select c.CID, c.CName from customers c where rating>8
/* output:
CID CName
406 rithu
82
407 abhi
408 rohan
413 nitya
414 jayanth
415 rujith */
83
Query13: Display the names of departments using order by statement.
select Dname from Depart order by Dname asc
/* output:
Dname
food
house keeping
management
security
service */
Query14: Find the details of the customer whose age is between 20 and 30.
select * from customers where age between 20 and 30
/* output:
CID CName Cmobile age crating
403 janu 9997776663 20 7
405 sreekar9997776665 21 8
406 rithu 9997776666 30 9 */
Query15: find the ID and name of managers who belong to department 5 and
tirupathi.
select M_id, M_name from manager where DID=5 and M_Address='tirupathi'
/* output:
M_id M_name
605 jansi
606 rupa */
Query16: Find the total number of hotels that are in this city.
SELECT COUNT(HID) AS num_hotels FROM Hotel;
/* output:
num_hotels
15 */
Query17: Update the contact of a particular staff.
update staff set s_mobile='7672044500' where s_sid=513
/* output:
84
s_sname DID s_mobile s_sid
vicky 1 8889997771 501
ram 2 8889997772 502
kiran 3 8889997773 503
sunny 4 8889997774 504
vijay 5 8889997775 505
mahi 1 8889997776 506
ravi 2 8889997777 507
arpitha 3 8889997778 508
ramya 4 8889997779 509
siri 5 8889997710 510
adhi 1 8889997711 511
keerthi 2 8889997712 512
anshu 3 7672044500 513
akrythi 4 8889997714 514
ashok 5 8889997715 515 */
Query18: Insert a column name called R_cost with datatype as money and constraint
as null in rom table and insert values in it.
alter table Room add R_cost money null
update Room set R_cost=3000 where R_number=10 or R_number=12 or R_number=13
update Room set R_cost=3250 where R_number=17 or R_number=19 or R_number=20
update Room set R_cost=3500 where R_number=23 or R_number=24 or R_number=26
update Room set R_cost=3750 where R_number=27 or R_number=30 or R_number=31
update Room set R_cost=4000 where R_number=34 or R_number=37 or R_number=40
/* output:
R_type R_number R_floor R_cost
A 10 1 3000.00
A 12 1 3000.00
A 13 2 3000.00
A 17 4 3250.00
A 19 3 3250.00
A 20 3 3250.00
85
N 23 2 3500.00
N 24 2 3500.00
N 26 5 3500.00
N 27 5 3750.00
N 30 4 3750.00
N 31 3 3750.00
N 34 1 4000.00
N 37 2 4000.00
A 40 2 4000.00 */
Query19: Find the name of the hotel whose name starts with b and having atleast five
characters.
select Hname from hotel where Hname like 'b_%'
/* output:
Hname
baghvan
banjaar */
Query20: Display the average of all the facilities costs.
select avg(F_cost) as Avg_fac_cost from Facilities_available
/* output:
Avg_fac_cost
2120.00 */
Query21: Find the mobile number of staff whose name ends with i.
select s_mobile from staff where s_name like '%i'
/* output:
s_mobile
8889997776
8889997777
8889997710
8889997711
8889997712
8889997714 */
86
Query22: create a view from customers which includes CID, CName and mobile
number of customers of age >=30.
create view customer_details as
select CID, CName, Cmobile
from customers where age>=30
select * from customer_details
/* output:
CID CName Cmobile
406 rithu 9997776666
407 abhi 9997776667
408 rohan 9997776668
411 rehman9997776611
412 priya 9997776612
413 nitya 9997776613
414 jayanth9997776614
415 rujith 9997776615 */
Query23: Find the booking id of customer who booked the room 19.
select b.B_id from Booking b, Room r where b.R_number=r.R_number and
r.R_number=19
/* output:
B_id
305 */
Query24: Display the top five cid's of customers.
select top(5) CID from customer
/* output:
CID
101
102
103
104
105 */
87
Query25: Find the ID's and count of ID's of customers whose age is greater than 25
( use group by statement).
select CID, count(CID) as count from customers
where age>25 group by CID
/* output:
CID count
406 1
407 1
408 1
411 1
412 1
413 1
414 1
415 1
416 1
417 1 */
88
select s_name from staff s,Depart D where D.Dname='food' and s.DID=D.DID
/*output:
s_name
ram
ravi
keerthi */
Query 28: Display the names of mangers who belongs to security and house keeping
department. ( use UNION)
select m.M_name from manager m,Depart D,hotel h where D.Dname='security'
and m.DID=D.DID and m.HID=h.HID
UNION
select m.M_name from manager m,Depart D,hotel h where D.Dname='house keeping'
and m.DID=D.DID and m.HID=h.HID
/*output:
M_name
meera
neha
reshma */
Query 29: Find the booking id who booked roomtype as ac.
select b.B_id from Room r,Booking b where b.R_number=r.R_number and r.R_type='A'
/*output:
B_id
301
302
303
304
305
306
315*/
Query 30: Find cid, cname and from customer whose age is minimum
select CID,CName,age from customers where age=(select min(age) from customers)
/*output:
89
CID CName age
410 shetal 10 */
90
CHAPTER 4. CONCLUSION AND FUTUREWORK
Conclusion
In conclusion, the toll plaza database schema presented above provides a solid foundation
for managing and maintaining a toll plaza system. It encompasses essential entities such as
toll plazas, lanes, vehicles, customers, transactions, payments, users, roles, admin,
operators, supervisors, audit logs, vehicle owners, vehicle registration, toll plaza operators,
toll rates, toll violations, and toll violation fines.By utilizing this database schema, the toll
plaza system can efficiently store and retrieve information about toll plaza locations, lanes,
vehicle types, customers, and transactions. It enables the system to track and record details
of each transaction, including the vehicle involved, the toll plaza and lane used, the
customer responsible, and the corresponding payment.The inclusion of tables such as
vehicle owners and vehicle registration allows for the management of vehicle ownership
and registration details, providing a comprehensive view of vehicle-related information
within the toll plaza.
Overall, this database schema promotes efficient data management, accurate transaction
tracking, and robust user access control for a toll plaza system. It serves as a foundation
for implementing additional features and functionalities to meet specific requirements and
improve the overall operation and maintenance of the toll plaza system.
Future Work
In the future, the toll plaza database can be further enhanced to incorporate advanced
technologies and features. One area of future work involves the integration of artificial
intelligence (AI) and machine learning (ML) algorithms. By leveraging AI and ML, the
toll plaza database can analyze historical transaction data, traffic patterns, and user
behavior to predict traffic congestion, optimize toll rates, and allocate resources effectively.
Additionally, the database could be expanded to include geospatial data, allowing for more
precise location-based analytics and the implementation of dynamic tolling strategies.
Another potential advancement is the integration of blockchain technology to enhance
security, transparency, and trust in toll plaza transactions. By utilizing blockchain, the toll
plaza database can securely store transaction records, verify the authenticity of payments,
and enable secure peer-to-peer transactions. Furthermore, the future work could involve
the development of mobile applications or web portals that allow users to access their
transaction history, make payments, and receive personalized notifications and offers. This
would improve the overall user experience and provide convenience and flexibility for toll
plaza users.
91