0% found this document useful (0 votes)
2 views

inventory management

This case study outlines the implementation of an inventory management system for an e-mart grocery shop, detailing the creation of various entities such as Products, Suppliers, Orders, OrderItems, Stock, Customers, and Sales, each with their respective attributes and relationships. The document emphasizes the normalization process to eliminate data redundancy and improve database efficiency, alongside SQL commands for creating tables, inserting data, and managing transactions. Additionally, it covers the use of indexing, triggers, functions, and procedures to enhance database operations and maintain data integrity.

Uploaded by

21urcs030
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)
2 views

inventory management

This case study outlines the implementation of an inventory management system for an e-mart grocery shop, detailing the creation of various entities such as Products, Suppliers, Orders, OrderItems, Stock, Customers, and Sales, each with their respective attributes and relationships. The document emphasizes the normalization process to eliminate data redundancy and improve database efficiency, alongside SQL commands for creating tables, inserting data, and managing transactions. Additionally, it covers the use of indexing, triggers, functions, and procedures to enhance database operations and maintain data integrity.

Uploaded by

21urcs030
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/ 20

CASE STUDY USING ANY OF THE REAL LIFE APPLICATIONS

INVENTORY MANAGEMENT FOR A E-MART GROCERY SHOP

AIM

To creating case study using any of the real life database application for
inventory management for e-mart grocery the daily report of the grocery shop.

DESCRIPTION

 The details of grocery shop store in respective with all tables.


 Each entity(products,suppliers,order,orderitems,stock,customer,sales)

Contains unique and primary keys.

 The entity supplier ,order has binded with stock,product entities with
foreign key.
 All the entities are normalized and reduce duplicacy of records.
 We have to implement indexing on each tables of inventory
management for faster query execution.

INVENTORY MANAGEMENT FOR E-MART GROCERY SHOP


ENTITIES AND ATTRIBUTES

 Products: Attributes of products are ProductId,ProductName,Category,Price


 Supplier: Attributes of Suppliers are SupplierId,SupplierName,Address,phone
 Orders : Attributes of Orders are OrderID,SupplierId,OrderDate
 OrderItems: Attributes of OrderItems are OrderId,ProductId,Quantity
 Stock: Attributes of Stock are ProductId,Quantity
 Customers: Attributes of Customers are cus_id,cus_name,address,phone no.
 Sales: Attributes of Sales are salesId,cus_id,salesdate,totalamount.
NORMALIZATION TABLE:

1. First Normal Form (1NF): This is the most basic level of normalization. In 1NF,
each table cell should contain only a single value, and each column should have a
unique name. The first normal form helps to eliminate duplicate data and
simplify queries.

2. Second Normal Form (2NF): 2NF eliminates redundant data by requiring that
each non-key attribute be dependent on the primary key. This means that each
column should be directly related to the primary key, and not to other columns.

3. Third Normal Form (3NF): 3NF builds on 2NF by requiring that all non-key
attributes are independent of each other. This means that each column should
be directly related to the primary key, and not to any other columns in the same
table.

4. Boyce-Codd Normal Form (BCNF): BCNF is a stricter form of 3NF that ensures
that each determinant in a table is a candidate key. In other words, BCNF
ensures that each non-key attribute is dependent only on the candidate key.

5. Fourth Normal Form (4NF): 4NF is a further refinement of BCNF that ensures
that a table does not contain any multi-valued dependencies.

6. Fifth Normal Form (5NF): 5NF is the highest level of normalization and involves
decomposing a table into smaller tables to remove data redundancy and
improve data integrity.
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
Category VARCHAR(50),
Price DECIMAL(10,2)
);
Query OK, 0 rows affected (0.16 sec)
mysql> desc Products;

CREATE TABLE Suppliers (


SupplierID INT PRIMARY KEY,
SupplierName VARCHAR(50),
Address VARCHAR(100),
Phone VARCHAR(20)
);
Query OK, 0 rows affected (0.06 sec)
mysql> desc Suppliers;

CREATE TABLE Orders (


OrderID INT PRIMARY KEY,
SupplierID INT,
OrderDate DATE,
CONSTRAINT FK_Orders_Suppliers FOREIGN KEY (SupplierID) REFERENCES
Suppliers(SupplierID)
);
Query OK, 0 rows affected (0.05 sec)
mysql> desc Orders;

CREATE TABLE OrderItems (


OrderID INT,
ProductID INT,
Quantity INT,
CONSTRAINT PK_OrderItems PRIMARY KEY (OrderID, ProductID),
CONSTRAINT FK_OrderItems_Orders FOREIGN KEY (OrderID) REFERENCES
Orders(OrderID),
CONSTRAINT FK_OrderItems_Products FOREIGN KEY (ProductID) REFERENCES
Products(ProductID)
);
Query OK, 0 rows affected (0.04 sec)
mysql> desc OrderItems;
CREATE TABLE Stock (
ProductID INT PRIMARY KEY,
Quantity INT,
CONSTRAINT FK_Stock_Products FOREIGN KEY (ProductID) REFERENCES
Products(ProductID)
);
Query OK, 0 rows affected (0.03 sec)
mysql> desc Stock;

CREATE TABLE Customers (


CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(50),
Address VARCHAR(100),
Phone VARCHAR(20)
);
Query OK, 0 rows affected (0.02 sec)
mysql> desc Customers;

CREATE TABLE Sales (


SaleID INT PRIMARY KEY,
CustomerID INT,
SaleDate DATE,
TotalAmount DECIMAL(10,2),
CONSTRAINT FK_Sales_Customers FOREIGN KEY (CustomerID) REFERENCES
Customers(CustomerID)
);
Query OK, 0 rows affected (0.07 sec)
mysql> desc Sales;

mysql>INSERT INTO Products (ProductID, ProductName, Category, Price VALUES


(1, 'Apples', 'Fruit', 1.50), (2, 'Bananas', 'Fruit', 1.20),(3, 'Oranges', 'Fruit', 2.00),
(4, 'Milk', 'Dairy', 3.50),(5, 'Eggs', 'Dairy', 2.00),(6, 'Bread', 'Bakery', 2.50),
(7, 'Cereal','Breakfast', 3.00),(8, 'Pasta', 'Pantry', 1.50),(9, 'Rice', 'Pantry', 2.00),(10, 'Beans',
'Pantry', 1.00);
Query OK, 10 rows affected (0.07 sec)
select *from Products;
mysql> INSERT INTO Suppliers (SupplierID, SupplierName, Address, Phone)VALUES
(1, 'ABC Produce', '123 Main St', '555-1234'), (2, 'XYZ Dairy', '456 Oak St', '555-5678'),
(3, '123 Bakery', '789 Maple Ave', '555-9012'),(4, 'DEF Meats', '234 Elm St', '555-3456'),
(5, 'GHI Seafood', '567 Pine St', '555-7890'),(6, 'LMN Grocery', '890 Cedar St', '555-1234'),
(7, 'PQR Beverages', '123 Oak St', '555-5678'),(8, 'STU Snacks', '456 Maple Ave',
'5559012'), (9, 'VWX Frozen Foods', '789 Elm St', '555-3456'),(10, 'YZA Canned Goods',
'234 Pine St', '555-7890');
Query OK, 10 rows affected (0.01 sec)
mysql> select *from Suppliers;

mysql> INSERT INTO Orders (OrderID, SupplierID, OrderDate) VALUES


(1, 1, '2023-05-10'), (2, 2, '2023-05-10'),(3, 3, '2023-05-11'),(4, 4, '2023-05-11'),
(5, 5, '2023-05-12'),(6, 6, '2023-05-12'),(7, 7, '2023-05-13'),(8, 8, '2023-05-13'),
(9, 9, '2023-05-14'),(10, 10, '2023-05-14');
Query OK, 10 rows affected (0.01 sec)
mysql> select *from Orders;
mysql>INSERT INTO OrderItems ( OrderID, ProductID, Quantity) VALUES
(1, 1, 10),(1, 2, 5),(2, 3, 8),(2, 4, 2),(3, 5, 12),(3, 6, 3),(4, 7, 4),(4, 8, 6),(5, 9, 2),(5, 10, 1);
Query OK, 10 rows affected (0.00 sec)
mysql> select *from OrderItems;

mysql>INSERT INTO Stock (ProductID, Quantity )VALUES (1, 100), (2, 50),(3, 200),
(4, 75),(5, 150),(6, 25),(7, 100),(8, 80),(9, 30), (10, 20);
Query OK, 10 rows affected (0.01 sec)
select *from Stock;
mysql> INSERT INTO Customers (CustomerID, CustomerName, Address, Phone)VALUES
(1, 'John','kk nagar', '555-1234'),(2, 'Jane','jk nagar', '555-5678'), (3, 'Bob', 'jj nagar', '555-
4321'),(4, 'Sara','mn nagar', '555-8765'),(5, 'Mike','ss nagar', '555-9876'), (6, 'Emily','rr nagar',
'555-2468'), (7, 'David','st nagar', '555-1357'),(8, 'Rachel','vo nagar', '555-3691'), (9, 'Tom','sk
nagar', '555-8024'),(10, 'Megan','ms nagar', '555-7410');
Query OK, 10 rows affected (0.02 sec)
select *from Customers;

mysql> INSERT INTO Sales (SaleID, CustomerID,SaleDate, TotalAmount)VALUES


(1, 1,'2023-05-01', 25.00), (2, 2,'2023-05-02', 15.00),(3, 3,'2023-05-03', 40.00),(4, 4,'2023-05-
04', 20.00), (5, 5,'2023-05-05', 30.00), (6, 6,'2023-05-06', 12.50), (7, 7,'2023-05-07', 15.00),
(8, 8,'2023-05-08', 22.00),(9, 9,'2023-05-09', 18.00), (10, 10,'2023-05-10', 10.00);
Query OK, 10 rows affected (0.01 sec)
select *from Sales;

mysql> SELECT *FROM Customers WHERE CustomerName = 'John' OR Address = 'jj


nagar';

mysql> SELECT *FROM Products WHERE Category = 'Fruit' AND Price BETWEEN 1.00
AND 5.00;

mysql> SELECT COUNT(*) AS TotalProducts, AVG(Price) AS AvgPrice, MAX(Price) AS


MaxPrice, MIN(Price) AS MinPrice FROM Products;
mysql> SELECT *FROM Suppliers JOIN Orders ON Suppliers.SupplierId =
Orders.SupplierId;

mysql> SELECT * FROM Suppliers LEFT OUTER JOIN Orders ON Suppliers.SupplierId =


Orders.SupplierId UNION SELECT *FROM Suppliers RIGHT OUTER JOIN Orders ON
Suppliers.SupplierId = Orders.SupplierId;

mysql> start transaction;


Query OK, 0 rows affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into Products values(11,'Biscuits','Dairy',2.50);


Query OK, 1 row affected (0.05 sec)

mysql> savepoint stu;


Query OK, 0 rows affected (0.00 sec)

mysql> select *from Products;

mysql> update Products set Price =5.00 where ProductName='Rice';


Query OK, 1 row affected (0.03 sec)
mysql> savepoint pro;
Query OK, 0 rows affected (0.00 sec)
select *from Products;
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)
mysql> update Products set Price=8.00 where ProductName='Eggs';
Query OK, 0 rows affected (0.00 sec)
mysql> Savepoint det;
Query OK, 0 rows affected (0.00 sec)
Select * from Products;
mysql> ROLLBACK to SAVEPOINT det;
Query OK, 0 rows affected (0.00 sec)
select * from Products;

mysql> create user harini;


Query OK, 0 rows affected (0.16 sec)
mysql> create user muthu;
Query OK, 0 rows affected (0.01 sec)
mysql> create user vishnu;
Query OK, 0 rows affected (0.01 sec)
mysql> Grant all privileges on Products to harini;
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for harini;
+------------------------------------------------------------+
| Grants for harini@% |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO `harini`@`%` |
| GRANT ALL PRIVILEGES ON `muthu`.`products` TO `harini`@`%` |
+------------------------------------------------------------+
mysql> Grant insert, update,delete on Suppliers to vishnu;
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for vishnu;
+---------------------------------------------------------------------+
| Grants for vishnu@% |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `vishnu`@`%` |
| GRANT INSERT, UPDATE, DELETE ON `muthu`.`suppliers` TO `vishnu`@`%` |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> REVOKE all on Products from harini;
Query OK, 0 rows affected (0.02 sec)
mysql> show grants for harini;
+------------------------------------+
| Grants for harini@% |
+------------------------------------+
| GRANT USAGE ON *.* TO `harini`@`%` |
+------------------------------------+
1 row in set (0.00 sec)
create trigger trigg1 before insert or update or delete on Products for each row
begin
raise_application_error(-20010,'You cannot do manipulation');
end;
/
Trigger TRIGG1 compiled
delete from Products where Productname='Beans';

Error report -
ORA-20010: You cannot do manipulation
ORA-06512: at "HARINI.TRIGG1", line 2
ORA-04088: error during execution of trigger 'HARINI.TRIGG1'

drop trigger trigg1;


Trigger TRIGG1 dropped.

CREATE FUNCTION totalProductsname()


RETURNS INT
BEGIN
DECLARE total INT;
SELECT COUNT(*) INTO total FROM products;
RETURN total;
END
Function TOTALPRODUCTSNAME compiled.

CREATE PROCEDURE updatePrice (IN productID INT, IN newPrice DECIMAL(10,2))


BEGIN
UPDATE products SET price = newPrice WHERE productId = productID;
END

Procedure UPDATEPRICE compiled

CREATE VIEW sample_Products as select ProductID,ProductName,Category,Price from


Products;

View SAMPLE_PRODUCTS created.

SELECT DISTINCT * FROM sample_Products;


INSERT INTO sample_Products VALUES(15,'Rusk','DairyProduct',6.00);
1 row inserted.
Select *From sample_Products;

UPDATE sample_Products SET ProductName='Milkgova' WHERE ProductId=4;


1 row updated.
Select *from Sample_Products;
Create Synonym Prodcuts_sym for Products;

Synonym PRODCUTS_SYM created.

CREATE INDEX product_index on Products(ProductName);

Index PRODUCT_INDEX created.

drop index product_index;

truncate table Sales;

Table SALES truncated.

Truncate table Customers;

Table CUSTOMERS truncated.

truncate table Stock;

Table STOCK truncated.

truncate table OrderItems;

Table ORDERITEMS truncated.

truncate table Orders;

Table ORDERS truncated.


truncate table Suppliers;

Table SUPPLIERS truncated.

truncate table Products;

Table PRODUCTS truncated.

drop table Sales;

Table SALES dropped.

drop table Customers;

Table CUSTOMERS dropped.

drop table stock;

Table STOCK dropped.

drop table OrderItems;

Table ORDERITEMS dropped.

drop table Orders;

Table ORDERS dropped.

drop table suppliers;


Table SUPPLIERS dropped.

drop table Products;

Table PRODUCTS dropped.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy