0% found this document useful (0 votes)
9 views74 pages

DBMS Project

Walmart has faced significant challenges in inventory management and sales tracking, leading to discrepancies in financial reports. Issues include inventory inaccuracies, theft, and manual data entry errors. The document also discusses normalization of supplier data and various SQL operations for managing customer, sale, product, and employee tables.
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)
9 views74 pages

DBMS Project

Walmart has faced significant challenges in inventory management and sales tracking, leading to discrepancies in financial reports. Issues include inventory inaccuracies, theft, and manual data entry errors. The document also discusses normalization of supplier data and various SQL operations for managing customer, sale, product, and employee tables.
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/ 74

CASE STUDY

One company that faced problems with accurately counting sales in retail
management is Walmart. Walmart has encountered various issues related to
inventory management and sales tracking, leading to discrepancies in their
financial reports and inventory levels.
Walmart is one of the world's largest retail chains, and like many retailers of its
scale, it has faced challenges in effectively counting and managing sales in its
numerous stores. Here's a more detailed description of some of the problems
Walmart has encountered and the strategies they've employed to address them:

Inventory Accuracy:
Walmart's vast inventory and the sheer volume of products sold in its stores
made it challenging to maintain accurate inventory counts.Inventory
inaccuracies could lead to stockouts, overstock situations, and difficulties in
tracking the sales of specific items.

Theft and Shrinkage:


Retail stores, including Walmart, often experience theft and shrinkage, which
can result in discrepancies between actual sales and recorded sales.This posed a
significant challenge for accurately counting sales and managing profitability.

Manual Data Entry Errors:


Manual data entry in the sales and inventory systems could result in human
errors, leading to inaccurate sales figures and inventory levels.

FUNCTIONALITY:
Employee Training and Development
Loss Prevention
Automatic Calculation of amount
NORMALISATION

SUPPLIER’S TABLE:

Supplier_id Supplier_name Department_id Email Phone_number Address


Sup-001 Randeep Groc [email protected] 7772323894 Delhi
om
Sup-002 Ashi Stat a13@gmail. 9726473654 London
com
Sup-003 Erica Drs e14@gmail. 7748372489 Mumbai
com
Sup-004 Shaheer Cnpr [email protected] 8672637264 UttarPra
om desh
Sup-005 Dhruv Cos d16@gmail. 86838768375 Bangalor
com e

1.First Normal Form (1NF):


- Ensure that each column contains only atomic (indivisible) values.
- In your table, it appears to already be in 1NF since each column has atomic
values.

2. Second Normal Form (2NF):


- To achieve 2NF, we must first identify a candidate key. In this case,
"Supplier_id" seems to be a candidate key.
- Next, we need to remove partial dependencies, which means that non-key
columns depend on only part of the candidate key.
- "Department_id" is a foreign key and depends on the "Supplier_id," so it
doesn't create partial dependencies.
- To normalize to 2NF, no further action is required.
3. Third Normal Form (3NF):
- In 3NF, we aim to remove transitive dependencies. No non-key column should
depend on another non-key column.
- "Department_id" may depend on "Supplier_id" (indicating which department
the supplier is associated with). This implies a transitive dependency.
- To achieve 3NF, you can create a new table for departments and link it using
the "Department_id." This new table might be called "DEPARTMENT_TABLE."
SUPPLIER_TABLE:
- Supplier_id (Primary Key)
- Supplier_name
- Department_id (Foreign Key)
- Email
- Phone_number
- Address

DEPARTMENT_TABLE:
- Department_id (Primary Key)
- Department_name

ENTITY RELATIONSHIP DIAGRAM:


DATA DEFINITION LANGUAGE

1.Add a new column to the Customer table:


ALTER TABLE customer_table ADD address varchar(10);
Table altered.

2.Rename a column in the Customer table:


ALTER TABLE customer_table RENAME COLUMN address TO add_customer;
Table altered.

3.Delete a column from the Customer table:


ALTER TABLE customer_table DROP COLUMN add_customer;
Table altered.

4.Add a foreign key constraint to the Customer table:


ALTER TABLE customer_table ADD CONSTRAINT FK_Customer FOREIGN KEY
(product_id) REFERENCES product_table(product_id);
Table altered
5.Add a new column to the Sale table:
ALTER TABLE sale_table ADD year number;
Table altered.

6.Rename a column in the Sale table:


ALTER TABLE sale_table RENAME COLUMN year TO year_sale;
Table altered.

7.Delete a column from the Sale table:


ALTER TABLE sale_table DROP COLUMN year_sale;
Table altered.

8.Add a new column to the Product table:


ALTER TABLE product_table ADD sold_qty number;
Table altered.

9.Rename a column in the Product table:


ALTER TABLE product_table RENAME COLUMN sold_qty TO qty_sold;
Table altered.

10.Delete a column from the Product table:


ALTER TABLE product_table DROP COLUMN qty_sold;
Table altered.

11.Add a new column to the Supplier table:


ALTER TABLE supplier_table ADD age number;
Table altered.

12.Rename a column in the Supplier table:


ALTER TABLE supplier_table RENAME COLUMN age TO age_supplier;
Table altered.

13.Delete a column from the Supplier table:


ALTER TABLE supplier_table DROP COLUMN age_supplier;
Table altered.

14.Add a new column to the Employee table:


ALTER TABLE employee_table ADD date_of_birth date;
Table altered.

15.Rename a column in the Employee table:


ALTER TABLE employee_table RENAME COLUMN date_of_birth TO dob;
Table altered.

16.Delete a column from the Employee table:


ALTER TABLE employee_table DROP COLUMN dob;
Table altered.

17.Rename CUSTOMERS_TABLE to NEW_CUSTOMERS_TABLE:


ALTER TABLE CUSTOMER_TABLE RENAME TO NEW_CUSTOMERS_TABLE
Table altered.

18.TRUNCATE SALE_TABLE
TRUNCATE TABLE SALE_TABLE
Table truncated.

19.DROP CUSTOMER TABLE:


DROP TABLE CUSTOMER_TABLE;
Table dropped.
20.Create a view to get the product sales information:
CREATE VIEW ProductSales AS
SELECT p.product_id, p.product_name, s.quantity_sold, s.sale_amount
FROM PRODUCT_TABLE p
JOIN SALE_TABLE s ON p.product_id = s.product_id
View created.

21.Create a view to get employee details with department id:


CREATE VIEW EmployeeDetails AS
SELECT e.Employee_id, e.employee_name, p.department_id
FROM EMPLOYEE_TABLE e
JOIN PRODUCT_TABLE p ON e.department_id = p.department_id
View created.

22.Create a DEPARTMENT_TABLE to store department information:


CREATE TABLE DEPARTMENT_TABLE (
Department_id VARCHAR(50) PRIMARY KEY,
Department_name VARCHAR(100) NOT NULL);
Table created.

23. DROP DEPRTMENT_TABLE:


DROP TABLE DEPARTMENT_TABLE;
Table dropped.

24. Create a view to get customer purchase history:


CREATE VIEW CustomerPurchaseHistory AS
SELECT c.Customer_id, c.Customer_name, p.Product_id, p.Product_Name,
c.Purchase_Date, c.Amount
FROM CUSTOMER_TABLE c
JOIN PRODUCT_TABLE p ON c.Product_Id = p.Product_id
View created.

25. Create a view to get the total sales for each product:
CREATE VIEW TotalProductSales AS
SELECT p.Product_id, p.Product_Name, SUM(s.Sale_amount) AS Total_Sales
FROM PRODUCT_TABLE p
LEFT JOIN SALE_TABLE s ON p.Product_id = s.Product_id
GROUP BY p.Product_id, p.Product_Name;
View created.

26. Rename the "Category" column in the PRODUCT_TABLE to


"Product_Category":
ALTER TABLE PRODUCT_TABLE RENAME COLUMN Category TO Product_Category;
Table altered.

27. Create a PAYMENT_METHOD_TABLE to store payment method


information:
CREATE TABLE PAYMENT_METHOD_TABLE (
PaymentMethod_id VARCHAR(50) PRIMARY KEY,
PaymentMethod_name VARCHAR(100) NOT NULL);
Table created.

28. Drop the PAYMENT_METHOD_TABLE:


DROP TABLE PAYMENT_METHOD_TABLE;
Table dropped.

29. Create a view to get the total revenue generated from sales:
CREATE VIEW TotalRevenue AS
SELECT SUM(Sale_amount) AS Revenue
FROM SALE_TABLE;
View created.

30. Create a view to get the top-selling products:


CREATE VIEW TopSellingProducts AS
SELECT p.Product_id, p.Product_Name, SUM(s.Quantity_sold) AS Total_Sold
FROM PRODUCT_TABLE p
JOIN SALE_TABLE s ON p.Product_id = s.Product_id
GROUP BY p.Product_id, p.Product_Name
ORDER BY Total_Sold DESC;
View created.

31.DROP THE VIEW:


DROP VIEW TOTALREVENUE;
View dropped.
DATA MANIPULATION LANGUAGE

32.Update an employee’s name based on their employee id:


UPDATE employee_table SET employee_name = 'Logi' WHERE employee_id = 'grocma-
021';
1 row updated.

33.Update an employee's salary based on their employee ID:


UPDATE employee_table SET salary = 23000 WHERE employee_id = 'statsal-0004';
1 row updated.

34.UPDATE the department of an employee based on their employee ID:


UPDATE employee_table SET department_id = 'groc' WHERE employee_id='drssal-0007';
1 row updated.

35.Update the manager of an employee based on their employee ID:


UPDATE employee_table SET employee_id ='cosma-026' WHERE employee_id = 'cossal-
0012';
1 row updated.

36.Update the information of an employee using employee_id:


UPDATE employee_table SET employee_name = 'Navani', department_id='groc' WHERE
employee_id ='statma-022';
1 row updated.

37.Update the price of a product based on its ProductID:


UPDATE product_table SET price = 200 WHERE product_id = 'groc-nuts-0077';
1 row updated.
38.Update the quantity in stock for a product based on its ProductID:
UPDATE product_table SET qty = '250g' WHERE Product_id = 'groc-nuts-0077';
1 row updated.

39.Update the supplier of a product based on its DepartmentID:


UPDATE supplier_table SET supplier_id = 'sup-009' WHERE department_id ='cos' ;
1 row updated.

40.Update the product name based on its ProductID:


UPDATE product_table SET product_name = 'Permanent Marker' WHERE product_id =
'stat-mrkr-0092';
1 row updated.

41.Update the customer's name based on their CustomerID:


UPDATE customer_table SET customer_name = 'Vishal' WHERE customer_id = 'cid-043';
1 row updated.

42.Update the customer's contact information (e.g., email, or phone


number):
UPDATE customer_table SET email = '[email protected]', phone_number ='8766564865'
WHERE customer_id = 'cid-045';
1 row updated.

43.Update the customer's phone number;


UPDATE customer_table SET phone_number = '8634567898'WHERE customer_id ='cid-
045';
1 row updated.

44.Update the sale amount based on the SaleID:


UPDATE sale_table SET sale_amount ='2000' WHERE sale_id ='sal-01';
1 row updated.

45.Update the product ID based on the SaleID:


UPDATE sale_table SET product_id = 'drs-mi-0057' WHERE sale_id = 'sal-34';
1 row updated.

46.Increasing the price of all product by 5%


UPDATE PRODUCT_TABLE
SET Price = Price * 1.05;
100 rows updated.

47.Inserting a new customer:


INSERT INTO CUSTOMER_TABLE (Bill_no, Customer_id, Customer_name, Product_Id,
Email, Phone_number, Employee_Id, Qty, Purchase_Date, Amount)
VALUES ('B1', 'C1', 'John Doe', 'P1', '[email protected]', 1234567890, 'E1', '2', '10-mar-2023',
20);
1 row created.

48.Updating customer email:


UPDATE CUSTOMER_TABLE
SET Email = '[email protected]'
WHERE Customer_id = 'cid-005';
1 row updated.

49.Deleting a row from customer table:


DELETE FROM CUSTOMER_TABLE
WHERE Customer_id = 'cid-005';
1 row deleted.
50. Find customers who purchased a specific product:
SELECT Customer_name
FROM CUSTOMER_TABLE
WHERE Product_Id = 'cnpr-clgt-0001';

Customer Name
Gautam

51.Inserting the new value into sale table:


INSERT INTO SALE_TABLE (Sale_id, Product_id, Quantity_sold, Sale_amount)
VALUES ('S1', 'P1', '5', 50);
1 row created.

52. Update quantity sold in a sale record:


UPDATE SALE_TABLE
SET Quantity_sold = '10'
WHERE Sale_id = 'sal-01';
1 row updated.

53.Delete a sale record:


DELETE FROM SALE_TABLE
WHERE Sale_id = 'sal-01';
1 row deleted.

54.Find products with no sale record:


SELECT Product_id
FROM PRODUCT_TABLE
WHERE Product_id NOT IN (SELECT DISTINCT Product_id FROM SALE_TABLE);

Product_id
drs-hltr-0050
drs-blgn-0053
groc-vngr-0084
stat-shpn-0093
drs-sdrs-0054
drs-cctl-0052
cnpr-clgt-0001
groc-spcs-0087
drs-ctot-0059
groc-ktup-0082
stat-crtp-0099
groc-nuts-0077
stat-ersr-0090
groc-slt-0068
groc-ooil-0070
cnpr-arfr-0034
stat-pen-0088
drs-wrap-0046
cos-fmst-0019
groc-cerl-0065
groc-myns-0081
cnpr-tisu-0026
groc-bksd-0086
drs-tunc-0051
groc-rice-0063
cos-bbwp-0035
groc-flr-0066
drs-shrt-0047
stat-pcwp-0030
groc-teap-0078
cnpr-lnfr-0040
groc-cofep-0079
cnpr-hdsp-0021
cos-ssrn-0023
groc-butr-0072
groc-bkpw-0085
stat-alfl-0029
drs-bdcn-0044
groc-mstrd-0083
cos-lpbm-0024
drs-slp-0062
stat-rulr-0100
stat-mrkr-0092
cos-fcln-0013
cnpr-lndr-0015
cos-ctsw-0022
stat-hglt-0091
cos-bbpd-0039
drs-shth-0048
stat-cpncl-0094
55.Insert a new employee:
INSERT INTO EMPLOYEE_TABLE (Employee_id, Employee_name, Department_id,
Position, Hire_date, Salary)
VALUES ('E2', 'Jane Smith', 'D1', 'Manager', '01-may-2023', 60000);
1 row created.

56. Find suppliers in a specific department:


SELECT * FROM SUPPLIER_TABLE
WHERE Department_id = 'cos';
Supplier_id Supplier_name Department_id Email Phone_number Address
sup-009 Dhruv cos [email protected] 8638768375 Bangalore

57.Update supplier’s Phone number

UPDATE SUPPLIER_TABLE
SET Phone_number = 9999999999
WHERE Supplier_id = 'sup-002';
1 row updated

58.Delete a supplier:
DELETE FROM SUPPLIER_TABLE
WHERE Supplier_id = 'sup-003';
1 row deleted.

59. List suppliers with email addresses:


SELECT Supplier_name, Email
FROM SUPPLIER_TABLE;

SUPPLIER_NAME EMAIL
-------------------------------------------------- -------------------------
Randeep [email protected]
Ashi [email protected]
Shaheer [email protected]
Dhruv [email protected]

60. Select all products in a specific department:


SELECT PRODUCT_ID FROM PRODUCT_TABLE
where department_id='stat';

PRODUCT_ID
--------------------------------------------------
stat-alfl-0029
stat-pcwp-0030
stat-zlbg-0031
stat-btrs-0032
stat-ltbl-0033
stat-pncl-0089
stat-pen-0088
stat-ersr-0090
stat-hglt-0091
stat-mrkr-0092
stat-shpn-0093
stat-cpncl-0094
stat-cryn-0095
stat-glpn-0096
stat-mcpn-0097
stat-blpn-0098
stat-crtp-0099
stat-rulr-0100
61.Select suuplier with a phone_number starting with a specific number:
SELECT * FROM SUPPLIER_TABLE WHERE Phone_number LIKE '863%';
SUPPLIER_ID SUPPLIER_NAME DEPARTMENT_ID EMAIL PHONE_NUMBER
------------------------------------------------------------------------------------------------------------
ADDRESS
-------------------------
sup-009 Dhruv cos [email protected] 8638768375
Bangalore
DATA INTEGRITY CONSTRAINT

62.NOT NULL:
create table product_table(product_id varchar(50) NOT NULL,product_name
varchar(100),department_id varchar(50),category varchar(100),price number,qty
varchar(50));
Table created

63.UNIQUE:
create table customer_table(bill_no varchar(25) unique,customer_id
varchar(25),customer_name varchar(25),product_id varchar(25),email varchar(25),
phone_number number,employee_id varchar(25),qty varchar(25),purchase_date date,amount
number);
Table created

64.CHECK:
create table employee_table(employee_id varchar(50) primary key,employee_name
varchar(50),department_id varchar(50),position varchar(50),hire_date date,salary number
CHECK(salary>0));
Table created

65.PRIMARY KEY:
create table supplier_table( supplier_id varchar(50) primary key,supplier_name
varchar(50),department_id varchar(25),email varchar(25),phone_number number,address
varchar(25));
Table created

66.FOREIGN KEY:
create table sale_table(sale_id varchar(25) ,product_id varchar(25),quantity_sold
varchar(25),sale_amount number,PRIMARY KEY(sale_id),FOREIGN KEY(product_id)
REFERENCES product_table(product_id));
Table created
AGGREGATE FUNCTIONS AND SORTING

67.Calculating the average amount in customer table


Select avg(amount)from customer_table;

AVG(AMOUNT)
-----------------------
880.647059

68.Calculating the minimum amount in customer table


select min(amount)from customer_table ;

MIN(AMOUNT)
-----------------------
25

69.Calculating the maximum amount in customer table


select max(amount)from customer_table;

MAX(AMOUNT)
------------------------
4866

70.Calculating the number of bills


select count(bill_no)from customer_table;

COUNT(BILL_NO)
----------------------------
51
71.Calculating the average amount in employee table
select avg(salary)from employee_table;

AVG(SALARY)
----------------------
24538.4615

72.Calculating the minimum amount in employee table


select min(salary)from employee_table;

MIN(SALARY)
---------------------
20000

73.Calculating the minimum amount in employee table


select max(salary)from employee_table;
MAX(SALARY)
-----------------------
60000

74.Calculating the number of employee


select count(employee_id)from employee_table;

COUNT(EMPLOYEE_ID)
--------------------------------------
26

75.Converting the initials to capital


select initcap (employee_name) from employee_table;
INITCAP(EMPLOYEE_NAME)
--------------------------------------------------
Logi
Navani
Aishu
Renu
Prabhu
Abi
Ramya
Sastri
Jane Smith
Ariya
Gokila
Ravi
Kavi
Kani
Siva
Nithya
Ram
Arun
Kaviya
Praveen
Krishna
Kanika
Janu
Nisha
Thara
Nakshu
76.Converting the employee name into upper case
select upper (employee_name) from employee_table;

UPPER(EMPLOYEE_NAME)
--------------------------------------------------
LOGI
NAVANI
AISHU
RENU
PRABHU
ABI
RAMYA
SASTRI
JANE SMITH
ARIYA
GOKILA
RAVI
KAVI
KANI
SIVA
NITHYA
RAM
ARUN
KAVIYA
PRAVEEN
KRISHNA
KANIKA
JANU
NISHA
THARA
NAKSHU

77.Converting the employee name into lower case


select lower (employee_name) from employee_table;

LOWER(EMPLOYEE_NAME)
--------------------------------------------------
logi
navani
aishu
renu
prabhu
abi
ramya
sastri
jane smith
ariya
gokila
ravi
kavi
kani
siva
nithya
ram
arun
kaviya
praveen
krishna
kanika
janu
nisha
thara
nakshu

78.Calculating average price in product_table:


select avg(price)from product_table

AVG(PRICE)
------------------
433.36

79.Calculating minimum price in product_table:


select min(price)from product_table ;

MIN(PRICE)
-----------------
10

80.Calculating maximum price in product_table:


select max(price)from product_table ;

MAX(PRICE)
-------------------
5000

81.Counting the number of products:


select count(product_id)from product_table ;

COUNT(PRODUCT_ID)
-----------------------------------
100
82.Calculating average price in sale_table:
select avg(sale_amount)from sale_table;

AVG(SALE_AMOUNT)
---------------------------------
880.352941

83.Calculating minimum price in sale_table:


select min(sale_amount)from sale_table;

MIN(SALE_AMOUNT)
---------------------------------
0

84.Calculating maximum price in sale_table:


select max(sale_amount)from sale_table;

MAX(SALE_AMOUNT)
----------------------------------
4866

85.Counting the number of sales:


select count(sale_id)from sale_table;

COUNT(SALE_ID)
------------------------------
51

86.Calculate the total number of employees in each position:


SELECT Position, COUNT(*) FROM EMPLOYEE_TABLE GROUP BY Position;

POSITION COUNT(*)
-------------------------------------------------- ----------
Manager 6
Supervisor 5
Salesperson 15

87.Calculate the total number of sales made by each employee:


SELECT Employee_Id,COUNT(*) FROM CUSTOMER_TABLE GROUP BY
Employee_Id;

EMPLOYEE_ID COUNT(*)
------------------------- ----------------------------
drssal-0008 2
grocsal-0001 3
cnprsal-0014 5
drssal-0009 2
grocsal-0003 3
grocsal-0002 1
drssal-0007 4
cosma-024 3
grocsup-001 1
cnprsup-005 1
drssup-003 1
cnprma-025 2
cnprsal-0013 2
cnprsal-0015 3
cossal-0010 2
cossal-0012 1
cossal-0011 1
statsal-0006 3
statma-022 1
statsal-0004 2
statsal-0005 3
drsma-023 2
grocma-021 1
cossup-004 1
statsup-002 1

88.Find the number of products with a price greater than a specific value
SELECT COUNT(*) FROM PRODUCT_TABLE WHERE Price >3800;

COUNT(*)
--------------------
1

89.Find the average phone number length for customers:


SELECT AVG(LENGTH(Phone_number)) FROM CUSTOMER_TABLE;

AVG(LENGTH(PHONE_NUMBER))
-------------------------
10

90.Calculate the total salary expense for each department:


DEPARTMENT_ID SUM(SALARY)
-------------------------------------------------- ---------------------------
groc 165000
drs 95000
cos 115000
cnpr 115000
stat 88000
D1 60000

91.Extract the month from a date column:


SELECT EXTRACT(MONTH FROM Hire_date) FROM EMPLOYEE_TABLE;
EXTRACT(MONTHFROMHIRE_DATE)
--------------------------------------------------------
11
12
1
5
1
6
9
7
5
10
12
11
12
11
1
3
2
1
7
9
7
2
2
3
10
8
92.Find the average length of supplier addresses
SELECT AVG(LENGTH(Address)) FROM SUPPLIER_TABLE;

AVG(LENGTH(ADDRESS))
--------------------------------------
8.25

93.Find the average length of email addresses:


SELECT AVG(LENGTH(Email)) FROM CUSTOMER_TABLE;

AVG(LENGTH(EMAIL))
------------------
16

94. Calculate the total quantity of products brought by each customer


SELECT Customer_id, SUM(Qty) FROM CUSTOMER_TABLE GROUP BY Customer_id;

CUSTOMER_ID SUM(QTY)
------------------------- ----------
cid-001 2
cid-002 1
cid-003 2
cid-004 3
cid-006 2
cid-007 4
cid-008 2
cid-009 2
cid-010 3
cid-011 3
cid-012 2
cid-013 3
cid-014 6
cid-015 3
cid-016 3
cid-017 2
cid-018 1
cid-019 2
cid-020 5
cid-021 2
cid-022 2
cid-023 1
cid-024 3
cid-025 6
cid-026 2
cid-027 2
cid-028 5
cid-030 3
cid-031 1
cid-032 2
cid-033 3
cid-034 2
cid-35 2
cid-036 1
cid037 3
cid-038 3
cid-039 2
cid-040 2
cid-041 1
cid-042 2
cid-043 2
cid-044 1
cid-045 1
cid-046 2
cid-047 1

95.Find the average price of products in a specific category:


SELECT AVG(Price) FROM PRODUCT_TABLE WHERE department_id='cnpr';

AVG(PRICE)
------------------
169.380952

96. Find the average length of product names:


SELECT AVG(LENGTH(Product_Name)) FROM PRODUCT_TABLE;

AVG(LENGTH(PRODUCT_NAME))
-------------------------
10.97

JOINS

97.Inner join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id :
Select product_table.product_name, product_table.price,customer_table.bill_no from
product_table inner join customer_table on
product_table.product_id=customer_table.product_id;

PRODUCT_NAME PRICE BILL_NO


---------------------------------------------------------------------------------------------------------------
Colgate_Toothpaste 40 bid-018
Pepsodent_Toothpaste 97 bid-019
dabur_Toothpaste 112 bid-020
Indulekha_shampoo 204 bid-021
Dove_Soap 65 bid-003
Nivea_Soap 145 bid-022
Body_Lotion 201 bid-023
Deodorant 265 bid-025
Toilet_Paper 199 bid-024
Facial_Cleanser 274 bid-026
Hand_Sanitizer 25 bid-027
Hand_Sanitizer 25 bid-028
Dish Soap 75 bid-031
Conditioner 550 bid-032
Facial Razor 199 bid-030
Contact Lens Solution 241 bid-014
Dishwasher Detergent 600 bid-012
Trash Bags 115 bid-046
Ziploc Bags 199 bid-047
Batteries 270 bid-037
Light Bulbs 120 bid-038
Light Bulbs 120 bid-052
Baby Diaper 1200 bid-034
Baby Shampoo 95 bid-016
Baby Lotion 138 bid-051
Maxi Dress 699 bid-029
Skater Dress 1585 bid-013
A line Dress 380 bid-017
Shift Dress 999 bid-009
Peplum Dress 899 bid-033
Off Soulder 1700 bid-040
Little Black Dress 1800 bid-001
Midi Dress 2000 bid-045
Puff Sleeve Dress 1622 bid-004
Pencils 35 bid-039
Asymmetrical Dress 469 bid-050
Tiered Dress 1199 bid-010
Pasta 39 bid-049
Sugar 80 bid-041
Pepper 189 bid-048
Cooking Oil 120 bid-007
Canned Beans 110 bid-011
Canned Tomatoes 100 bid-006
Peanut Butter 279 bid-015
Oats 195 bid-008
Pasta Sauce 99 bid-002
Crayon 10 bid-035
Gel Pen 180 bid-036
Mechanical Pencil 20 bid-042
Mechanical Pencil 20 bid-043
Ball Pen 100 bid-044

98.Right Outer join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id :
select product_table.product_name, product_table.price,customer_table.bill_no from
product_table right outer join customer_table on
product_table.product_id=customer_table.product_id;
PRODUCT_NAME PRICE BILL_NO
---------------------------------------------------------------------------------------------------------------
Colgate_Toothpaste 40 bid-018
Pepsodent_Toothpaste 97 bid-019
dabur_Toothpaste 112 bid-020
Indulekha_shampoo 204 bid-021
Dove_Soap 65 bid-003
Nivea_Soap 145 bid-022
Body_Lotion 201 bid-023
Deodorant 265 bid-025
Toilet_Paper 199 bid-024
Facial_Cleanser 274 bid-026
Hand_Sanitizer 25 bid-027
Hand_Sanitizer 25 bid-028
Dish Soap 75 bid-031
Conditioner 550 bid-032
Facial Razor 199 bid-030
Contact Lens Solution 241 bid-014
Dishwasher Detergent 600 bid-012
Trash Bags 115 bid-046
Ziploc Bags 199 bid-047
Batteries 270 bid-037
Light Bulbs 120 bid-038
Light Bulbs 120 bid-052
Baby Diaper 1200 bid-034
Baby Shampoo 95 bid-016
Baby Lotion 138 bid-051
Maxi Dress 699 bid-029
Skater Dress 1585 bid-013
A line Dress 380 bid-017
Shift Dress 999 bid-009
Peplum Dress 899 bid-033
Off Soulder 1700 bid-040
Little Black Dress 1800 bid-001
Midi Dress 2000 bid-045
Puff Sleeve Dress 1622 bid-004
Pencils 35 bid-039
Asymmetrical Dress 469 bid-050
Tiered Dress 1199 bid-010
Pasta 39 bid-049
Sugar 80 bid-041
Pepper 189 bid-048
Cooking Oil 120 bid-007
Canned Beans 110 bid-011
Canned Tomatoes 100 bid-006
Peanut Butter 279 bid-015
Oats 195 bid-008
Pasta Sauce 99 bid-002
Crayon 10 bid-035
Gel Pen 180 bid-036
Mechanical Pencil 20 bid-042
Mechanical Pencil 20 bid-043
Ball Pen 100 bid-044

99.Left Outer join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id :
select product_table.product_name, product_table.price,customer_table.bill_no from
product_table left outer join customer_table on
product_table.product_id=customer_table.product_id;

PRODUCT_NAME PRICE
BILL_NO
---------------------------------------------------------------------------------------------------- ---------- -
------------------------
Little Black Dress 1800 bid-001
Pasta Sauce 99 bid-002
Dove_Soap 65 bid-003
Puff Sleeve Dress 1622 bid-004
Canned Tomatoes 100 bid-006
Cooking Oil 120 bid-007
Oats 195 bid-008
Shift Dress 999 bid-009
Tiered Dress 1199 bid-010
Canned Beans 110 bid-011
Dishwasher Detergent 600 bid-012
Skater Dress 1585 bid-013
Contact Lens Solution 241 bid-014
Peanut Butter 279 bid-015
Baby Shampoo 95 bid-016
A line Dress 380 bid-017
Colgate_Toothpaste 40 bid-018
Pepsodent_Toothpaste 97 bid-019
dabur_Toothpaste 112 bid-020
Indulekha_shampoo 204 bid-021
Nivea_Soap 145 bid-022
Body_Lotion 201 bid-023
Toilet_Paper 199 bid-024
Deodorant 265 bid-025
Facial_Cleanser 274 bid-026
Hand_Sanitizer 25 bid-027
Hand_Sanitizer 25 bid-028
Maxi Dress 699 bid-029
Facial Razor 199 bid-030
Dish Soap 75 bid-031
Conditioner 550 bid-032
Peplum Dress 899 bid-033
Baby Diaper 1200 bid-034
Crayon 10 bid-035
Gel Pen 180 bid-036
Batteries 270 bid-037
Light Bulbs 120 bid-038
Pencils 35 bid-039
Off Soulder 1700 bid-040
Sugar 80 bid-041
Mechanical Pencil 20 bid-042
Mechanical Pencil 20 bid-043
Ball Pen 100 bid-044
Midi Dress 2000 bid-045
Trash Bags 115 bid-046
Ziploc Bags 199 bid-047
Pepper 189 bid-048
Pasta 39 bid-049
Asymmetrical Dress 469 bid-050
Baby Lotion 138 bid-051
Light Bulbs 120 bid-052
Halter Dress 560
Ball Gown 2500
Vinegar 70
Lifebuoy_Soap 154
Cocktail Dress 1000
Sun Dress 670
Sharpener 70
Spices 100
CutOut Dress 1950
Ketchup 108
Correction Tape 125
Nuts 200
Erasers 40
Salt 40
Olive Oil 352
Air Freshner 275
Pens 50
Wrap Dress 2500
Face Moisturer 355
Cereal 152
Mayonnaise 185
Tissues 100
Tunic Dress 280
Baking Soda 24
Toothbrush 20
Baby Wipes 90
Rice 291
Flour 45
Shirt Dress 5000
Plastic Wrap 200
Tea pack 90
Laundry Fabric Softener 257
Coffee pack 216
Hand Soap 45
Sunscreen 499
Butter 56
Baking Powder 23
Clinic_Plus 105
Aluminium Foil 375
Bodycon Dress 800
Lip Balm 250
Mustard 30
Slip Dress 760
Ruler 10
Permanent Marker 100
Dove_Shampoo 599
Laundry_Detergent 230
Cotton Swabs 20
Highlighter 100
Baby Powder 88
Sheath Dress 720
Colour pencils 120

100.Full join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id :

select product_table.product_id,product_table.product_name,
product_table.price,product_table.qty,customer_table.bill_no from product_table full join
customer_table on product_table.product_id=customer_table.product_id;

PRODUCT_ID PRODUCT_NAME PRICE QTY BILL_NO


-------------------------------------------------- --------------------------------------------------------------
cnpr-clgt-0001 Colgate_Toothpaste 40 105gm bid-018
cnpr-psdt-0002 Pepsodent_Toothpaste 97 150gm bid-019
cnpr-dbur-0003 dabur_Toothpaste 112 200gm bid-020
cnpr-idlk-0004 Indulekha_shampoo 204 200ml bid-021
cnpr-clnp-0005 Clinic_Plus 105 175ml
cnpr-dove-0006 Dove_Shampoo 599 1l
cnpr-dvsp-0007 Dove_Soap 65 100g bid-003
cnpr-lfsp-0008 Lifebuoy_Soap 154 125g
cnpr-nvsp-0009 Nivea_Soap 145 125g bid-022
cos-bdln-0010 Body_Lotion 201 400ml bid-023
cos-dodt-0011 Deodorant 265 200ml bid-025
cnpr-tlpr-0012 Toilet_Paper 199 2roll bid-024
cos-fcln-0013 Facial_Cleanser 274 125ml bid-026
cnpr-hsnz-0014 Hand_Sanitizer 25 100ml bid-027
cnpr-hsnz-0014 Hand_Sanitizer 25 100ml bid-028
cnpr-lndr-0015 Laundry_Detergent 230 1kg
cnpr-dwsh-0016 Dish Soap 75 1kg bid-031
cnpr-brsh-0017 Toothbrush 20 1 brush
cos-cdnr-0018 Conditioner 550 200ml bid-032
cos-fmst-0019 Face Moisturer 355 100g
cos-rzor-0020 Facial Razor 199 3 razors bid-030
cnpr-hdsp-0021 Hand Soap 45 100ml
cos-ctsw-0022 Cotton Swabs 20 100 pcs
cos-ssrn-0023 Sunscreen 499 50g
cos-lpbm-0024 Lip Balm 250 10g
cos-ctln-0025 Contact Lens Solution 241 120ml bid-014
cnpr-tisu-0026 Tissues 100 50sheets
cnpr-dwdt-0027 Dishwasher Detergent 600 1kg bid-012
cnpr-trbg-0028 Trash Bags 115 30bags bid-046
stat-alfl-0029 Aluminium Foil 375 4pack
stat-pcwp-0030 Plastic Wrap 200 1kg
stat-zlbg-0031 Ziploc Bags 199 10bags bid-047
stat-btrs-0032 Batteries 270 6cells bid-037
stat-ltbl-0033 Light Bulbs 120 1bulb bid-038
stat-ltbl-0033 Light Bulbs 120 1bulb bid-052
cnpr-arfr-0034 Air Freshner 275 1bottle
cos-bbwp-0035 Baby Wipes 90 1pack
cos-bbdp-036 Baby Diaper 1200 2pack bid-034
cnpr-bbsp-0037 Baby Shampoo 95 100ml bid-016
cos-bbln-0038 Baby Lotion 138 200ml bid-051
cos-bbpd-0039 Baby Powder 88 100g
cnpr-lnfr-0040 Laundry Fabric Softener 257 1kg
drs-maxi-0041 Maxi Dress 699 1 dress bid-029
drs-sktr-0042 Skater Dress 1585 2 Dress bid-013
drs-alne-0043 A line Dress 380 1 Dress bid-017
drs-bdcn-0044 Bodycon Dress 800 1 Dress
drs-shft-0045 Shift Dress 999 1 Dress bid-009
drs-wrap-0046 Wrap Dress 2500 4 Dress
drs-shrt-0047 Shirt Dress 5000 6 Dress
drs-shth-0048 Sheath Dress 720 2 Dress
drs-pplm-0049 Peplum Dress 899 1 Dress bid-033
drs-hltr-0050 Halter Dress 560 1 Dress
drs-tunc-0051 Tunic Dress 280 2 Dress
drs-cctl-0052 Cocktail Dress 1000 3 Dress
drs-blgn-0053 Ball Gown 2500 1 Dress
drs-sdrs-0054 Sun Dress 670 1 Dress
drs-offs-0055 Off Soulder 1700 2 Dress bid-040
drs-ltbl-0056 Little Black Dress 1800 1 Dress bid-001
drs-midi-0057 Midi Dress 2000 1 Dress bid-045
drs-pfslv-0058 Puff Sleeve Dress 1622 1 Dress bid-004
stat-pncl-0089 Pencils 35 1 box bid-039
drs-ctot-0059 CutOut Dress 1950 2 Dress
drs-asym-0060 Asymmetrical Dress 469 1 Dress bid-050
drs-trd-0061 Tiered Dress 1199 1 Dress bid-010
drs-slp-0062 Slip Dress 760 1 Dress
groc-rice-0063 Rice 291 5kg
groc-psta-0064 Pasta 39 400g bid-049
groc-cerl-0065 Cereal 152 240g
groc-flr-0066 Flour 45 500g
groc-sugr-0067 Sugar 80 2kg bid-041
groc-slt-0068 Salt 40 2kg
groc-pepr-0069 Pepper 189 100g bid-048
groc-ooil-0070 Olive Oil 352 200ml
groc-coil-0071 Cooking Oil 120 1l bid-007
groc-butr-0072 Butter 56 100g
groc-beans-0073 Canned Beans 110 450g bid-011
groc-ctmts_0074 Canned Tomatoes 100 850g bid-006
groc-pnbtr-0075 Peanut Butter 279 510g bid-015
groc-oats-0076 Oats 195 1kg bid-008
groc-nuts-0077 Nuts 200 250g
groc-teap-0078 Tea pack 90 100g
groc-cofep-0079 Coffee pack 216 500g
groc-pstsc-0080 Pasta Sauce 99 400g bid-002
groc-myns-0081 Mayonnaise 185 800g
groc-ktup-0082 Ketchup 108 500g
groc-mstrd-0083 Mustard 30 100g
groc-vngr-0084 Vinegar 70 1l
groc-bkpw-0085 Baking Powder 23 50g
groc-bksd-0086 Baking Soda 24 100g
groc-spcs-0087 Spices 100 1kg
stat-pen-0088 Pens 50 1 pen
stat-ersr-0090 Erasers 40 5 erasers
stat-hglt-0091 Highlighter 100 5 pen
stat-mrkr-0092 Permanent Marker 100 10 pen
stat-shpn-0093 Sharpener 70 5 pieces
stat-cpncl-0094 Colour pencils 120 24 colours
stat-cryn-0095 Crayon 10 12 pieces bid-035
stat-glpn-0096 Gel Pen 180 3 pen bid-036
stat-mcpn-0097 Mechanical Pencil 20 1 pencil bid-042
stat-mcpn-0097 Mechanical Pencil 20 1 pencil bid-043
stat-blpn-0098 Ball Pen 100 10 pen bid-044
stat-crtp-0099 Correction Tape 125 1 tape
stat-rulr-0100 Ruler 10 1 ruler

101.Cross join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id :
select product_table.product_id,product_table.product_name,
product_table.price,customer_table.bill_no from product_table cross join customer_table
where product_table.product_id=customer_table.product_id;

PRODUCT_ID PRODUCT_NAME PRICE BILL_NO


-------------------------------------------------- --------------------------------------------------------------
cnpr-clgt-0001 Colgate_Toothpaste 40 bid-018
cnpr-psdt-0002 Pepsodent_Toothpaste 97 bid-019
cnpr-dbur-0003 dabur_Toothpaste 112 bid-020
cnpr-idlk-0004 Indulekha_shampoo 204 bid-021
cnpr-dvsp-0007 Dove_Soap 65 bid-003
cnpr-nvsp-0009 Nivea_Soap 145 bid-022
cos-bdln-0010 Body_Lotion 201 bid-023
cos-dodt-0011 Deodorant 265 bid-025
cnpr-tlpr-0012 Toilet_Paper 199 bid-024
cos-fcln-0013 Facial_Cleanser 274 bid-026
cnpr-hsnz-0014 Hand_Sanitizer 25 bid-027
cnpr-hsnz-0014 Hand_Sanitizer 25 bid-028
cnpr-dwsh-0016 Dish Soap 75 bid-031
cos-cdnr-0018 Conditioner 550 bid-032
cos-rzor-0020 Facial Razor 199 bid-030
cos-ctln-0025 Contact Lens Solution 241 bid-014
cnpr-dwdt-0027 Dishwasher Detergent 600 bid-012
cnpr-trbg-0028 Trash Bags 115 bid-046
stat-zlbg-0031 Ziploc Bags 199 bid-047
stat-btrs-0032 Batteries 270 bid-037
stat-ltbl-0033 Light Bulbs 120 bid-038
stat-ltbl-0033 Light Bulbs 120 bid-052
cos-bbdp-036 Baby Diaper 1200 bid-034
cnpr-bbsp-0037 Baby Shampoo 95 bid-016
cos-bbln-0038 Baby Lotion 138 bid-051
drs-maxi-0041 Maxi Dress 699 bid-029
drs-sktr-0042 Skater Dress 1585 bid-013
drs-alne-0043 A line Dress 380 bid-017
drs-shft-0045 Shift Dress 999 bid-009
drs-pplm-0049 Peplum Dress 899 bid-033
drs-offs-0055 Off Soulder 1700 bid-040
drs-ltbl-0056 Little Black Dress 1800 bid-001
drs-midi-0057 Midi Dress 2000 bid-045
drs-pfslv-0058 Puff Sleeve Dress 1622 bid-004
stat-pncl-0089 Pencils 35 bid-039
drs-asym-0060 Asymmetrical Dress 469 bid-050
drs-trd-0061 Tiered Dress 1199 bid-010
groc-psta-0064 Pasta 39 bid-049
groc-sugr-0067 Sugar 80 bid-041
groc-pepr-0069 Pepper 189 bid-048
groc-coil-0071 Cooking Oil 120 bid-007
groc-beans-0073 Canned Beans 110 bid-011
groc-ctmts_0074 Canned Tomatoes 100 bid-006
groc-pnbtr-0075 Peanut Butter 279 bid-015
groc-oats-0076 Oats 195 bid-008
groc-pstsc-0080 Pasta Sauce 99 bid-002
stat-cryn-0095 Crayon 10 bid-035
stat-glpn-0096 Gel Pen 180 bid-036
stat-mcpn-0097 Mechanical Pencil 20 bid-042
stat-mcpn-0097 Mechanical Pencil 20 bid-043
stat-blpn-0098 Ball Pen 100 bid-044

102.Inner join PRODUCT_TABLE and CUSTOMERS_TABLE on


Product_id and Email:
SELECT P.Product_id, P.Product_Name, C.Email
FROM PRODUCT_TABLE P
INNER JOIN CUSTOMER_TABLE C ON P.Product_id = C.Product_Id AND C.Email =
'[email protected]';
PRODUCT_ID PRODUCT_NAME EMAIL
-------------------------------------------------- -------------------------------------------------------------
groc-sugr-0067 Sugar [email protected]

103.Inner join PRODUCT_TABLE and EMPLOYEE_TABLE on


Department_Id and Employee_id:
SELECT P.Product_id, P.Product_Name, E.Employee_name
FROM PRODUCT_TABLE P
INNER JOIN EMPLOYEE_TABLE E ON P.Department_Id = E.Department_id AND
E.Employee_id = 'grocsal-0002';
PRODUCT_ID PRODUCT_NAME EMPLOYEE_NAME
-------------------------------------------------- --------------------------------------------------------------
groc-rice-0063 Rice Kavi
groc-psta-0064 Pasta Kavi
groc-cerl-0065 Cereal Kavi
groc-flr-0066 Flour Kavi
groc-sugr-0067 Sugar Kavi
groc-slt-0068 Salt Kavi
groc-pepr-0069 Pepper Kavi
groc-ooil-0070 Olive Oil Kavi
groc-coil-0071 Cooking Oil Kavi
groc-butr-0072 Butter Kavi
groc-beans-0073 Canned Beans Kavi
groc-ctmts_0074 Canned Tomatoes Kavi
groc-pnbtr-0075 Peanut Butter Kavi
groc-oats-0076 Oats Kavi
groc-nuts-0077 Nuts Kavi
groc-teap-0078 Tea pack Kavi
groc-cofep-0079 Coffee pack Kavi
groc-pstsc-0080 Pasta Sauce Kavi
groc-myns-0081 Mayonnaise Kavi
groc-ktup-0082 Ketchup Kavi
groc-mstrd-0083 Mustard Kavi
groc-vngr-0084 Vinegar Kavi
groc-bkpw-0085 Baking Powder Kavi
groc-bksd-0086 Baking Soda Kavi
groc-spcs-0087 Spices Kavi

104.Inner join PRODUCT_TABLE and SALES_TABLE on Product_id


and Sale_id:
SELECT P.Product_id, P.Product_Name, S.Sale_id
FROM PRODUCT_TABLE P
INNER JOIN SALE_TABLE S ON P.Product_id = S.Product_id;

PRODUCT_ID PRODUCT_NAME SALE_ID


----------------------------------------------------------------------------------------------------------------
cnpr-psdt-0002 Pepsodent_Toothpaste sal-02
cnpr-dbur-0003 dabur_Toothpaste sal-03
cnpr-idlk-0004 Indulekha_shampoo sal-04
cnpr-clnp-0005 Clinic_Plus sal-05
cnpr-dove-0006 Dove_Shampoo sal-06
cnpr-dvsp-0007 Dove_Soap sal-07
cnpr-lfsp-0008 Lifebuoy_Soap sal-08
cnpr-nvsp-0009 Nivea_Soap sal-09
cos-bdln-0010 Body_Lotion sal-10
cos-dodt-0011 Deodorant sal-11
cnpr-tlpr-0012 Toilet_Paper sal-12
cnpr-hsnz-0014 Hand_Sanitizer sal-13
cnpr-dwsh-0016 Dish Soap sal-14
cnpr-brsh-0017 Toothbrush sal-15
cos-cdnr-0018 Conditioner sal-16
cos-rzor-0020 Facial Razor sal-17
cos-ctln-0025 Contact Lens Solution sal-18
cnpr-dwdt-0027 Dishwasher Detergent sal-19
cnpr-trbg-0028 Trash Bags sal-20
stat-zlbg-0031 Ziploc Bags sal-21
stat-btrs-0032 Batteries sal-22
stat-ltbl-0033 Light Bulbs sal-23
cos-bbdp-036 Baby Diaper sal-24
cnpr-bbsp-0037 Baby Shampoo sal-25
cos-bbln-0038 Baby Lotion sal-26
drs-maxi-0041 Maxi Dress sal-27
drs-sktr-0042 Skater Dress sal-28
drs-alne-0043 A line Dress sal-29
drs-shft-0045 Shift Dress sal-30
drs-pplm-0049 Peplum Dress sal-31
drs-offs-0055 Off Soulder sal-32
drs-ltbl-0056 Little Black Dress sal-33
drs-midi-0057 Midi Dress sal-34
drs-pfslv-0058 Puff Sleeve Dress sal-35
stat-pncl-0089 Pencils sal-47
drs-asym-0060 Asymmetrical Dress sal-36
drs-trd-0061 Tiered Dress sal-37
groc-psta-0064 Pasta sal-38
groc-sugr-0067 Sugar sal-39
groc-pepr-0069 Pepper sal-40
groc-coil-0071 Cooking Oil sal-41
groc-beans-0073 Canned Beans sal-42
groc-ctmts_0074 Canned Tomatoe sal-43
groc-pnbtr-0075 Peanut Butter sal-44
groc-oats-0076 Oats sal-45
groc-pstsc-0080 Pasta Sauce sal-46
stat-cryn-0095 Crayon sal-48
stat-glpn-0096 Gel Pen sal-49
stat-mcpn-0097 Mechanical Pencil sal-50
stat-blpn-0098 Ball Pen sal-51

105.Left join EMPLOYEE_TABLE and CUSTOMERS_TABLE on


Employee_id:
SELECT E.Employee_id, E.Employee_name, C.Customer_name
FROM EMPLOYEE_TABLE E
LEFT JOIN CUSTOMER_TABLE C ON E.Employee_id = C.Employee_Id;

EMPLOYEE_ID EMPLOYEE_NAME CUSTOMER_NAME


-------------------------------------------------- -------------------------------------------------- -----------
drssal-0008 Kaviya Amrin
grocsal-0001 Ravi Amritha
cnprsal-0014 Thara Akshitha
drssal-0009 Praveen Alagu Nivetha
grocsal-0003 Kani Atchaya
grocsal-0003 Kani Swarna
grocsal-0002 Kavi Sri Devi
drssal-0009 Praveen Leka
drssal-0007 Arun Latha
grocsal-0001 Ravi Keerthana
cnprsal-0014 Thara Swathy
drssal-0007 Arun Lalith
cosma-024 Renu Raja
grocsup-001 Abi Raja
cnprsup-005 Gokila Sri Devi
drssup-003 Sastri Vishwa
cnprma-025 Prabhu Gautam
cnprma-025 Prabhu Vibin
cnprsal-0014 Thara Suresh
cnprsal-0013 Nisha Vaibow
cnprsal-0015 Nakshu John
cossal-0010 Krishna Sadhan
cnprsal-0015 Nakshu Dharun
cossal-0010 Krishna Jessica
cnprsal-0014 Thara Aarav
cnprsal-0014 Thara Abinaya
drssal-0008 Kaviya Abinaya
cosma-024 Renu Abinaya
cnprsal-0015 Nakshu Diviya
cosma-024 Renu Sheru
drssal-0007 Arun Lucas
cossal-0011 Kanika Leo
statsal-0006 Ram Ameera
statsal-0006 Ram Raxel
statma-022 Navani Alexa
statsal-0004 Siva Rowan
statsal-0005 Nithya Ramani
drsma-023 Aishu Lira
grocma-021 Logi Rohan
statsal-0005 Nithya Kiran
statsal-0005 Nithya Zoe
statsal-0006 Ram Zufy
drssal-0007 Arun Swazil
cnprsal-0013 Nisha Yamini
statsal-0004 Siva Yariz
grocsal-0001 Ravi Vaishali
grocsal-0003 Kani Joshen
drsma-023 Aishu Charu
cossup-004 Ariya Dharshan
statsup-002 Ramya Rakshan
E2 Jane Smith
cosma-026 Janu

106.Inner join CUSTOMERS_TABLE and EMPLOYEE_TABLE on


Employee_id:
SELECT C.Customer_name, C.Employee_Id, E.Employee_name
FROM CUSTOMER_TABLE C
INNER JOIN EMPLOYEE_TABLE E ON C.Employee_Id = E.Employee_id;

CUSTOMER_NAME EMPLOYEE_ID EMPLOYEE_NAME


----------------------------------------------------------------------------------------------------
Amrin drssal-0008 Kaviya
Amritha grocsal-0001 Ravi
Akshitha cnprsal-0014 Thara
Alagu Nivetha drssal-0009 Praveen
Atchaya grocsal-0003 Kani
Swarna grocsal-0003 Kani
Sri Devi grocsal-0002 Kavi
Leka drssal-0009 Praveen
Latha drssal-0007 Arun
Keerthana grocsal-0001 Ravi
Swathy cnprsal-0014 Thara
Lalith drssal-0007 Arun
Raja cosma-024 Renu
Raja grocsup-001 Abi
Sri Devi cnprsup-005 Gokila
Vishwa drssup-003 Sastri
Gautam cnprma-025 Prabhu
Vibin cnprma-025 Prabhu
Suresh cnprsal-0014 Thara
Vaibow cnprsal-0013 Nisha
John cnprsal-0015 Nakshu
Sadhan cossal-0010 Krishna
Dharun cnprsal-0015 Nakshu
Jessica cossal-0010 Krishna
Aarav cnprsal-0014 Thara
Abinaya cnprsal-0014 Thara
Abinaya drssal-0008 Kaviya
Abinaya cosma-024 Renu
Diviya cnprsal-0015 Nakshu
Sheru cosma-024 Renu
Lucas drssal-0007 Arun
Leo cossal-0011 Kanika
Ameera statsal-0006 Ram
Raxel statsal-0006 Ram
Alexa statma-022 Navani
Rowan statsal-0004 Siva
Ramani statsal-0005 Nithya
Lira drsma-023 Aishu
Rohan grocma-021 Logi
Kiran statsal-0005 Nithya
Zoe statsal-0005 Nithya
Zufy statsal-0006 Ram
Swazil drssal-0007 Arun
Yamini cnprsal-0013 Nisha
Yariz statsal-0004 Siva
Vaishali grocsal-0001 Ravi
Joshen grocsal-0003 Kani
Charu drsma-023 Aishu
Dharshan cossup-004 Ariya
Rakshan statsup-002 Ramya

107.Right join PRODUCT_TABLE and SALES_TABLE on Product_id:


SELECT P.Product_id, P.Product_Name, S.Sale_id
FROM PRODUCT_TABLE P
RIGHT JOIN SALE_TABLE S ON P.Product_id = S.Product_id;

PRODUCT_ID PRODUCT_NAME SALE_ID


--------------------------------------------------------------------------------------------------------------
cnpr-psdt-0002 Pepsodent_Toothpaste sal-02
cnpr-dbur-0003 dabur_Toothpaste sal-03
cnpr-idlk-0004 Indulekha_shampoo sal-04
cnpr-clnp-0005 Clinic_Plus sal-05
cnpr-dove-0006 Dove_Shampoo sal-06
cnpr-dvsp-0007 Dove_Soap sal-07
cnpr-lfsp-0008 Lifebuoy_Soap sal-08
cnpr-nvsp-0009 Nivea_Soap sal-09
cos-bdln-0010 Body_Lotion sal-10
cos-dodt-0011 Deodorant sal-11
cnpr-tlpr-0012 Toilet_Paper sal-12
cnpr-hsnz-0014 Hand_Sanitizer sal-13
cnpr-dwsh-0016 Dish Soap sal-14
cnpr-brsh-0017 Toothbrush sal-15
cos-cdnr-0018 Conditioner sal-16
cos-rzor-0020 Facial Razor sal-17
cos-ctln-0025 Contact Lens Solution sal-18
cnpr-dwdt-0027 Dishwasher Detergent sal-19
cnpr-trbg-0028 Trash Bags sal-20
stat-zlbg-0031 Ziploc Bags sal-21
stat-btrs-0032 Batteries sal-22
stat-ltbl-0033 Light Bulbs sal-23
cos-bbdp-036 Baby Diaper sal-24
cnpr-bbsp-0037 Baby Shampoo sal-25
cos-bbln-0038 Baby Lotion sal-26
drs-maxi-0041 Maxi Dress sal-27
drs-sktr-0042 Skater Dress sal-28
drs-alne-0043 A line Dress sal-29
drs-shft-0045 Shift Dress sal-30
drs-pplm-0049 Peplum Dress sal-31
drs-offs-0055 Off Soulder sal-32
drs-ltbl-0056 Little Black Dress sal-33
drs-midi-0057 Midi Dress sal-34
drs-pfslv-0058 Puff Sleeve Dress sal-35
stat-pncl-0089 Pencils sal-47
drs-asym-0060 Asymmetrical Dress sal-36
drs-trd-0061 Tiered Dress sal-37
groc-psta-0064 Pasta sal-38
groc-sugr-0067 Sugar sal-39
groc-pepr-0069 Pepper sal-40
groc-coil-0071 Cooking Oil sal-41
groc-beans-0073 Canned Beans sal-42
groc-ctmts_0074 Canned Tomatoes sal-43
groc-pnbtr-0075 Peanut Butter sal-44
groc-oats-0076 Oats sal-45
groc-pstsc-0080 Pasta Sauce sal-46
stat-cryn-0095 Crayon sal-48
stat-glpn-0096 Gel Pen sal-49
stat-mcpn-0097 Mechanical Pencil sal-50
stat-blpn-0098 Ball Pen sal-51

108.Inner join SUPPLIER_TABLE and PRODUCT_TABLE on


Department_id:
SELECT S.Supplier_name, S.Department_id, P.Product_Name
FROM SUPPLIER_TABLE S
INNER JOIN PRODUCT_TABLE P ON S.Department_id = P.Department_Id;

SUPPLIER_NAME DEPARTMENT_ID PRODUCT_NAME


---------------------------------------------------------------------------------------------------------------
Shaheer cnpr Colgate_Toothpaste
Shaheer cnpr Pepsodent_Toothpaste
Shaheer cnpr dabur_Toothpaste
Shaheer cnpr Indulekha_shampoo
Shaheer cnpr Clinic_Plus
Shaheer cnpr Dove_Shampoo
Shaheer cnpr Dove_Soap
Shaheer cnpr Lifebuoy_Soap
Shaheer cnpr Nivea_Soap
Dhruv cos Body_Lotion
Dhruv cos Deodorant
Shaheer cnpr Toilet_Paper
Dhruv cos Facial_Cleanser
Shaheer cnpr Hand_Sanitizer
Shaheer cnpr Laundry_Detergent
Shaheer cnpr Dish Soap
Shaheer cnpr Toothbrush
Dhruv cos Conditioner
Dhruv cos Face Moisturer
Dhruv cos Facial Razor
Shaheer cnpr Hand Soap
Dhruv cos Cotton Swabs
Dhruv cos Sunscreen
Dhruv cos Lip Balm
Dhruv cos Contact Lens Solution
Shaheer cnpr Tissues
Shaheer cnpr Dishwasher Detergent
Shaheer cnpr Trash Bags
Ashi stat Aluminium Foil
Ashi stat Plastic Wrap
Ashi stat Ziploc Bags
Ashi stat Batteries
Ashi stat Light Bulbs
Shaheer cnpr Air Freshner
Dhruv cos Baby Wipes
Dhruv cos Baby Diaper
Shaheer cnpr Baby Shampoo
Dhruv cos Baby Lotion
Dhruv cos Baby Powder
Shaheer cnpr Laundry Fabric Softener
Ashi stat Pencils
Randeep groc Rice
Randeep groc Pasta
Randeep groc Cereal
Randeep groc Flour
Randeep groc Sugar
Randeep groc Salt
Randeep groc Pepper
Randeep groc Olive Oil
Randeep groc Cooking Oil
Randeep groc Butter
Randeep groc Canned Beans
Randeep groc Canned Tomatoes
Randeep groc Peanut Butter
Randeep groc Oats
Randeep groc Nuts
Randeep groc Tea pack
Randeep groc Coffee pack
Randeep groc Pasta Sauce
Randeep groc Mayonnaise
Randeep groc Ketchup
Randeep groc Mustard
Randeep groc Vinegar
Randeep groc Baking Powder
Randeep groc Baking Soda
Randeep groc Spices
Ashi stat Pens
Ashi stat Erasers
Ashi stat Highlighter
Ashi stat Permanent Marker
Ashi stat Sharpener
Ashi stat Colour pencils
Ashi stat Crayon
Ashi stat Gel Pen
Ashi stat Mechanical Pencil
Ashi stat Ball Pen
Ashi stat Correction Tape
Ashi stat Ruler

109. Inner join CUSTOMERS_TABLE and SALES_TABLE on


Product_Id:
SELECT C.Customer_name, C.Product_Id, S.Sale_amount
FROM CUSTOMER_TABLE C
INNER JOIN SALE_TABLE S ON C.Product_Id = S.Product_id;

CUSTOMER_NAME PRODUCT_ID SALE_AMOUNT


---------------------------------------------------------------------------------------------
Amrin drs-ltbl-0056 3600
Amritha groc-pstsc-0080 99
Akshitha cnpr-dvsp-0007 130
Alagu Nivetha drs-pfslv-0058 4866
Atchaya groc-ctmts_0074 200
Swarna groc-coil-0071 480
Sri Devi groc-oats-0076 95
Leka drs-shft-0045 1998
Latha drs-trd-0061 3597
Keerthana groc-beans-0073 330
Swathy cnpr-dwdt-0027 1200
Lalith drs-sktr-0042 4755
Raja cos-ctln-0025 1116
Raja groc-pnbtr-0075 1116
Sri Devi cnpr-bbsp-0037 95
Vishwa drs-alne-0043 1140
Vibin cnpr-psdt-0002 194
Suresh cnpr-dbur-0003 112
Vaibow cnpr-idlk-0004 408
John cnpr-nvsp-0009 725
Sadhan cos-bdln-0010 402
Dharun cnpr-tlpr-0012 398
Jessica cos-dodt-0011 265
Aarav cnpr-hsnz-0014 224
Abinaya cnpr-hsnz-0014 224
Abinaya drs-maxi-0041 199
Abinaya cos-rzor-0020 199
Diviya cnpr-dwsh-0016 150
Sheru cos-cdnr-0018 1100
Lucas drs-pplm-0049 2400
Leo cos-bbdp-036 2400
Ameera stat-cryn-0095 30
Raxel stat-glpn-0096 180
Alexa stat-btrs-0032 540
Rowan stat-ltbl-0033 480
Ramani stat-pncl-0089 70
Lira drs-offs-0055 3400
Rohan groc-sugr-0067 80
Kiran stat-mcpn-0097 120
Zoe stat-mcpn-0097 120
Zufy stat-blpn-0098 200
Swazil drs-midi-0057 4000
Yamini cnpr-trbg-0028 115
Yariz stat-zlbg-0031 398
Vaishali groc-pepr-0069 378
Joshen groc-psta-0064 39
Charu drs-asym-0060 469
Dharshan cos-bbln-0038 276
Rakshan stat-ltbl-0033 480

110. Inner join PRODUCT_TABLE and SALES_TABLE on Product_id


and Sale_amount greater than a specific value:
SELECT P.Product_id, P.Product_Name, S.Sale_amount
FROM PRODUCT_TABLE P
INNER JOIN SALE_TABLE S ON P.Product_id = S.Product_id
WHERE S.Sale_amount > 3500;

PRODUCT_ID PRODUCT_NAME SALE_AMOUNT


--------------------------------------------------------------------------------------------------------------
drs-sktr-0042 Skater Dress 4755
drs-ltbl-0056 Little Black 3600
drs-midi-0057 Midi Dress 4000
drs-pfslv-0058 Puff Sleeve Dress 4866
drs-trd-0061 Tiered Dress 3597

111. Inner join PRODUCT_TABLE and SALES_TABLE on Product_id


and Quantity_sold greater than a specific value:
SELECT P.Product_id, P.Product_Name, S.Quantity_sold
FROM PRODUCT_TABLE P
INNER JOIN SALE_TABLE S ON P.Product_id = S.Product_id
WHERE S.Quantity_sold > 5;

PRODUCT_ID PRODUCT_NAME QUANTITY_SOLD


----------------------------------------------------------------------------------------------------------------
stat-mcpn-0097 Mechanical Pencil 6
PL\SQL PROCEDURE

CURSOR:
112.To calculate the amount in customer_table for each customer bu
referencing product_table and then update the amount column in
customer_table.
SET SERVEROUTPUT ON;
DECLARE
v_customer_id customer_table.customer_id%TYPE;
v_product_id customer_table.product_id%TYPE;
v_price product_table.price%TYPE;
v_qty customer_table.qty%TYPE;
v_amount customer_table.amount%TYPE;
CURSOR customer_cursor IS
SELECT customer_id, product_id, qty
FROM customer_table;
BEGIN
OPEN customer_cursor;
FETCH customer_cursor INTO v_customer_id, v_product_id, v_qty;
WHILE customer_cursor%FOUND LOOP
SELECT price INTO v_price
FROM product_table
WHERE product_id = v_product_id;
v_amount := v_price * CAST(v_qty AS NUMBER);
UPDATE customer_table
SET amount = v_amount
WHERE customer_id = v_customer_id;
FETCH customer_cursor INTO v_customer_id, v_product_id, v_qty;
END LOOP;
CLOSE customer_cursor;
COMMIT;
END;
/
PL/SQL procedure successfully completed

113.To calculate the quantity_sold and sale_amount in sale_table for each


sale referencing customer_table and then update the column in sale_table
DECLARE
CURSOR sale_cursor IS
SELECT sale_id, product_id
FROM sale_table;
sale_rec sale_cursor%ROWTYPE;
quantity_sold NUMBER;
sale_amount NUMBER;
BEGIN
FOR sale_rec IN sale_cursor
LOOP
quantity_sold := 0;
sale_amount := 0;
FOR cust_rec IN (
SELECT TO_NUMBER(Qty) AS qty
FROM customer_table
WHERE Product_Id = sale_rec.product_id
)
LOOP
quantity_sold := quantity_sold + cust_rec.qty;
END LOOP;
FOR cust_rec IN (
SELECT TO_NUMBER(Amount) AS amount
FROM customer_table
WHERE Product_Id = sale_rec.product_id
)
LOOP
sale_amount := sale_amount + cust_rec.amount;
END LOOP;
UPDATE sale_table s
SET (quantity_sold, sale_amount) = (
SELECT
NVL(SUM(TO_NUMBER(c.Qty)), 0) AS quantity_sold,
NVL(SUM(TO_NUMBER(c.Amount)), 0) AS sale_amount
FROM customer_table c
WHERE c.Product_Id = s.product_id);
END LOOP;
COMMIT;
END;
/
PL/SQL procedure successfully completed

114.To calculate the amount in customer_table and print it:


DECLARE
Bill_no VARCHAR(25);
Total_amount NUMBER := 0;
BEGIN
FOR rec IN (SELECT c.bill_no, c.product_id, c.qty, NVL(p.price, 0) AS price
FROM customer_table c
LEFT JOIN product_table p
ON c.product_id = p.product_id
ORDER BY c.bill_no) LOOP
Bill_no := rec.bill_no;
Total_amount := Total_amount + (rec.qty * rec.price);
DBMS_OUTPUT.PUT_LINE('Bill Number: ' || Bill_no || ', Total Amount: ' || (rec.qty *
rec.price));
END LOOP;
DBMS_OUTPUT.PUT_LINE('Total Amount for all products: ' || Total_amount);
END;
/

Bill Number: bid-001, Total Amount: 3600


Bill Number: bid-002, Total Amount: 99
Bill Number: bid-003, Total Amount: 130
Bill Number: bid-004, Total Amount: 4866
Bill Number: bid-005, Total Amount: 80
Bill Number: bid-006, Total Amount: 200
Bill Number: bid-007, Total Amount: 480
Bill Number: bid-008, Total Amount: 195
Bill Number: bid-009, Total Amount: 1998
Bill Number: bid-010, Total Amount: 3597
Bill Number: bid-011, Total Amount: 330
Bill Number: bid-012, Total Amount: 1200
Bill Number: bid-013, Total Amount: 4755
Bill Number: bid-014, Total Amount: 482
Bill Number: bid-015, Total Amount: 1116
Bill Number: bid-016, Total Amount: 95
Bill Number: bid-017, Total Amount: 1140
Bill Number: bid-018, Total Amount: 120
Bill Number: bid-019, Total Amount: 194
Bill Number: bid-020, Total Amount: 112
Bill Number: bid-021, Total Amount: 408
Bill Number: bid-022, Total Amount: 725
Bill Number: bid-023, Total Amount: 402
Bill Number: bid-024, Total Amount: 398
Bill Number: bid-025, Total Amount: 265
Bill Number: bid-026, Total Amount: 548
Bill Number: bid-027, Total Amount: 25
Bill Number: bid-028, Total Amount: 75
Bill Number: bid-029, Total Amount: 1398
Bill Number: bid-030, Total Amount: 199
Bill Number: bid-031, Total Amount: 150
Bill Number: bid-032, Total Amount: 1100
Bill Number: bid-033, Total Amount: 2697
Bill Number: bid-034, Total Amount: 2400
Bill Number: bid-035, Total Amount: 30
Bill Number: bid-036, Total Amount: 180
Bill Number: bid-037, Total Amount: 540
Bill Number: bid-038, Total Amount: 360
Bill Number: bid-039, Total Amount: 70
Bill Number: bid-040, Total Amount: 3400
Bill Number: bid-041, Total Amount: 80
Bill Number: bid-042, Total Amount: 60
Bill Number: bid-043, Total Amount: 60
Bill Number: bid-044, Total Amount: 200
Bill Number: bid-045, Total Amount: 4000
Bill Number: bid-046, Total Amount: 115
Bill Number: bid-047, Total Amount: 398
Bill Number: bid-048, Total Amount: 378
Bill Number: bid-049, Total Amount: 39
Bill Number: bid-050, Total Amount: 469
Bill Number: bid-051, Total Amount: 276
Bill Number: bid-052, Total Amount: 120
Total Amount for all products: 46354

PL/SQL procedure successfully completed.

115.To fetch data from supplier table:


DECLARE
v_Supplier_id SUPPLIER_TABLE.Supplier_id%TYPE;
v_Supplier_name SUPPLIER_TABLE.Supplier_name%TYPE;
v_Department_id SUPPLIER_TABLE.Department_id%TYPE;
v_Email SUPPLIER_TABLE.Email%TYPE;
v_Phone_number SUPPLIER_TABLE.Phone_number%TYPE;
v_Address SUPPLIER_TABLE.Address%TYPE;
CURSOR supplier_cursor IS
SELECT Supplier_id, Supplier_name, Department_id,Email, Phone_number, Address
FROM SUPPLIER_TABLE;
BEGIN
OPEN supplier_cursor;
LOOP
FETCH supplier_cursor INTO v_Supplier_id, v_Supplier_name, v_Department_id,
v_Email, v_Phone_number, v_Address;
EXIT WHEN supplier_cursor%NOTFOUND;
DBMS_OUTPUT. PUT_LINE('Supplier ID: '|| v_Supplier_id);
DBMS_OUTPUT.PUT_LINE('Supplier Name:'||v_Supplier_name) ;
DBMS_OUTPUT.PUT_LINE('Department ID:'||v_Department_id) ;
DBMS_OUTPUT.PUT_LINE('Email:' || v_Email);
DBMS_OUTPUT.PUT_LINE('Phone Number:'|| v_Phone_number);
DBMS_OUTPUT.PUT_LINE('Address: '||v_Address);
END LOOP;
CLOSE supplier_cursor;
END;
/
Supplier ID: sup-001
Supplier Name:Randeep
Department ID:groc
Email:[email protected]
Phone Number:7772323894
Address: Delhi
Supplier ID: sup-002
Supplier Name:Ashi
Department ID:stat
Email:[email protected]
Phone Number:9726473654
Address: London
Supplier ID: sup-003
Supplier Name:Erica
Department ID:drs
Email:[email protected]
Phone Number:7748372489
Address: Mumbai
Supplier ID: sup-004
Supplier Name:Shaheer
Department ID:cnpr
Email:[email protected]
Phone Number:8672637264
Address: Uttar Pradesh
Supplier ID: sup-009
Supplier Name:Dhruv
Department ID:cos
Email:[email protected]
Phone Number:8638768375
Address: Bangalore

PL/SQL procedure successfully completed.

TRIGGER:
116. Trigger to calculate the total amount for a customer's purchase when a
new purchase is made
CREATE OR REPLACE TRIGGER calculate_purchase_amount
BEFORE INSERT ON customer_table
FOR EACH ROW
DECLARE
purchase_amount NUMBER;
BEGIN
SELECT price * :new.qty
INTO purchase_amount
FROM product_table
WHERE product_id = :new.product_id;

:new.amount := purchase_amount;

DBMS_OUTPUT.PUT_LINE('Purchase Amount: ' || purchase_amount);


END;
/

Trigger created.

insert into customer_table values('bid-053','cid-048','Sara','groc-teap-


0078','[email protected]',9738274879,'grocsal-0001',2,'13-jan-2021',0);

Purchase Amount: 180

117.Trigger to calculate the difference of old salary and new salary after
updating the salary
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON employee_table
FOR EACH ROW
WHEN (NEW.salary > 0)
DECLARE
sal_diff NUMBER;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old Salary : ' || :OLD.salary);
dbms_output.put_line('New Salary : ' || :NEW.salary);
dbms_output.put_line('Salary Difference : ' || sal_diff);
END;
/

Trigger created.

update employee_table set salary='30000' where department_id='groc';


Old Salary : 30000
New Salary : 30000
Salary Difference : 0
Old Salary : 25000
New Salary : 30000
Salary Difference : 5000
Old Salary : 20000
New Salary : 30000
Salary Difference : 10000
Old Salary : 20000
New Salary : 30000
Salary Difference : 10000
Old Salary : 20000
New Salary : 30000
Salary Difference : 10000

118.To create a procedure to calculate the customer’s purchase amount:


CREATE OR REPLACE PROCEDURE update_bill_for_customer (
p_customer_id IN Customer_table.Customer_id%TYPE
) AS
v_total_amount INT := 0;
BEGIN

FOR cust_purchase IN (
SELECT Amount
FROM Customer_table
WHERE Customer_id = p_customer_id
) LOOP
v_total_amount := v_total_amount + cust_purchase.Amount;
END LOOP;

UPDATE Bill_table
SET Amount_to_be_paid = v_total_amount
WHERE customer_id = p_customer_id;

COMMIT;
EXCEPTION
WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);


END;
/
Package created.
BEGIN
update_bill_for_customer('cid-045');
END;
/
PL/SQL procedure successfully completed.

PACKAGE:
119.To create a package and inserting the values

CREATE OR REPLACE PACKAGE product_package AS


PROCEDURE insert_product(
p_product_id VARCHAR2,
p_product_name VARCHAR2,
p_department_id VARCHAR2,
p_category VARCHAR2,
p_price NUMBER,
p_qty VARCHAR2
);
END product_package;
/

Package created.

CREATE OR REPLACE PACKAGE BODY product_package AS


PROCEDURE insert_product(
p_product_id VARCHAR2,
p_product_name VARCHAR2,
p_department_id VARCHAR2,
p_category VARCHAR2,
p_price NUMBER,
p_qty VARCHAR2
) IS
BEGIN
INSERT INTO product_table (product_id, product_name, department_id, category, price,
qty)
VALUES ('&&p_product_id','&& p_product_name','&& p_department_id','&&
p_category','&& p_price','&& p_qty');
END insert_product;
END product_package;
/

Enter value for p_product_id: 001


Enter value for p_product_name: AISHU
Enter value for p_department_id: GROC
Enter value for p_category: GROCERY
Enter value for p_price: 43
Enter value for p_qty: 2

old : VALUES ('&&p_product_id','&& p_product_name','&& p_department_id','&&


p_category','&& p_price','&& p_qty');
new : VALUES ('001','AISHU','GROC','GROCERY','43','2');

120.To calculate the total salary of the specified department

CREATE OR REPLACE PACKAGE department_salary_package AS


PROCEDURE calculate_total_salary(p_department_id VARCHAR2, p_total_salary OUT
NUMBER);
END department_salary_package;
/

Package created.
CREATE OR REPLACE PACKAGE BODY department_salary_package AS
PROCEDURE calculate_total_salary(p_department_id VARCHAR2, p_total_salary OUT
NUMBER) IS
BEGIN
SELECT SUM(salary) INTO p_total_salary
FROM employee_table
WHERE department_id = p_department_id;
END calculate_total_salary;
END department_salary_package;
/

Package body created.

DECLARE
v_department_id VARCHAR2(50) := 'groc';
v_total_salary NUMBER;
BEGIN
department_salary_package.calculate_total_salary(v_department_id, v_total_salary);
DBMS_OUTPUT.PUT_LINE('Total Salary for Department ' || v_department_id || ': ' ||
v_total_salary);
END;
/

Total Salary for Department groc: 115000

PL/SQL procedure successfully completed.

EXCEPTION HANDLING:
121.To print the name of a customer when the given customer_id matches:
DECLARE
c_id customer_table.customer_id%type := 'cid-045';
c_name customer_table.customer_name%type ;
BEGIN
SELECT customer_name INTO c_name FROM customer_table
WHERE customer_id = c_id ;
DBMS_OUTPUT.PUT_LINE ( 'Name : ' || c_name ) ;
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line ( ' No such customer! ' ) ; WHEN
others THEN
dbms_output.put_line ( ' Error! ' ) ;
END ;
/
Name : Charu

PL/SQL procedure successfully completed.

CONCLUSION

Summarizing the key points:

1. PRODUCT_TABLE: This table stores information about products, including their unique
IDs (Product_id), names, department IDs (Department_Id), categories, prices, and quantities
(Qty). It serves as a central repository for product data.
2. CUSTOMERS_TABLE: This table is dedicated to customer information. It includes details
such as customer IDs (Customer_id), names, email addresses, phone numbers, and the IDs of
the products they purchased. It also tracks the purchase quantity, date, and amount.

3. SALES_TABLE: The Sales table records sales transactions. It includes Sale_id as a unique
identifier, Product_id to link to products in the Product table, the quantity sold
(Quantity_sold), and the sale amount (Sale_amount).

4. EMPLOYEE_TABLE: Employee information is stored in this table. It contains


Employee_id, Employee_name, Department_id to associate employees with specific
departments, job positions (Position), hire dates (Hire_date), and salaries (Salary).

5. SUPPLIER_TABLE: Suppliers' data is stored in this table. It includes Supplier_id as a


unique identifier, Supplier_name, Department_id to link suppliers with departments, email
addresses (Email), phone numbers, and physical addresses (Address).
BIBILIOGRAPHY

https://www.scribd.com/document/388067179/308864997-RETAIL-STORE-
MANAGEMENT-SYSTEM

http://ignousupport.blogspot.com/p/supermarket-retail-management-
system.html?m=1

You might also like