├── README.md └── images ├── new_er.png └── new_relational.png /README.md: -------------------------------------------------------------------------------- 1 | # Ecommerce Management DBMS Project 2 | 3 | As a part of our University Curriculum, we made this project for Database Management Systems (DBMS) - ITE1003.
4 | This project contains theoretical as well as implementation in SQL.
5 | If you liked the repo do :star: it. 6 | 7 | ## Pre-requisite 8 | 9 | Oracle SQL Server (or) Oracle Community Edition 10 | 11 | ## Contents 12 | 13 | - Mini world and Project Description 14 | - Basic structure 15 | - Functional requirements 16 | - Entity Relation (ER) diagram and constraints 17 | - Relational database schema 18 | - Implementation 19 | - Creating tables 20 | - Inserting data 21 | - Queries 22 | - Basic queries 23 | - PL/SQL function 24 | - Trigger function 25 | 26 | ## 1. Mini world and Description 27 | 28 | In this modern era of online shopping no seller wants to be left behind, moreover due to its simplicity the shift from offline selling model to an online selling model is witnessing a rampant growth.
29 | Therefore, as an engineer our job is to ease the path of this transition for the seller. 30 | Amongst many things that an online site requires the most important is a database system. Hence in this project we are planning to design a database where small clothing sellers can sell their product online. 31 | 32 | ## 2. Basic Structure 33 | 34 | ### 2.1 Functional requirement 35 | 36 | - A new user can register on the website. 37 | - A customer can see details of the product present in the cart 38 | - A customer can view his order history. 39 | - Admin can start a sale with certain discount on every product. 40 | - Customer can filter the product based on the product details. 41 | - A customer can add or delete a product from the cart. 42 | - A seller can unregister/ stop selling his product. 43 | - A seller/ customer can update his details. 44 | - Admin can view the products purchased on particular date. 45 | - Admin can view number of products sold on a particular date. 46 | - A customer can view the total price of product present in the cart unpurchased. 47 | - Admin can view details of customer who have not purchased anything. 48 | - Admin can view total profit earned from the website. 49 | 50 | ### 2.2 Entity Relation Diagram 51 | 52 | ![ER diagram](https://github.com/bhumijgupta/Ecommerce-management-DBMS-project/raw/master/images/new_er.png) 53 | 54 | ### 2.3 Relational Database Schema 55 | 56 | ![Relational diagram](https://github.com/bhumijgupta/Ecommerce-management-DBMS-project/raw/master/images/new_relational.png) 57 | 58 | ## 3. Implementation 59 | 60 | You can directly copy and paste all the commands from the text given here into the SQL console to create and insert values into your table. 61 | 62 | ### 3.1 Creating Tables 63 | 64 | ```sql 65 | CREATE TABLE Cart 66 | ( 67 | Cart_id VARCHAR(7) NOT NULL, 68 | PRIMARY KEY(Cart_id) 69 | ); 70 | 71 | CREATE TABLE Customer 72 | ( 73 | Customer_id VARCHAR(6) NOT NULL, 74 | c_pass VARCHAR(10) NOT NULL, 75 | Name VARCHAR(20) NOT NULL, 76 | Address VARCHAR(20) NOT NULL, 77 | Pincode NUMBER(6) NOT NULL, 78 | Phone_number_s number(10) NOT NULL, 79 | PRIMARY KEY (Customer_id), 80 | Cart_id VARCHAR(7) NOT NULL, 81 | FOREIGN KEY(Cart_id) REFERENCES cart(Cart_id) 82 | ); 83 | 84 | CREATE TABLE Seller 85 | ( 86 | Seller_id VARCHAR(6) NOT NULL, 87 | s_pass VARCHAR(10) NOT NULL, 88 | Name VARCHAR(20) NOT NULL, 89 | Address VARCHAR(10) NOT NULL, 90 | PRIMARY KEY (Seller_id) 91 | ); 92 | 93 | CREATE TABLE Seller_Phone_num 94 | ( 95 | Phone_num NUMBER(10) NOT NULL, 96 | Seller_id VARCHAR(6) NOT NULL, 97 | PRIMARY KEY (Phone_num, Seller_id), 98 | FOREIGN KEY (Seller_id) REFERENCES Seller(Seller_id) 99 | ON DELETE CASCADE 100 | ); 101 | 102 | CREATE TABLE Payment 103 | ( 104 | payment_id VARCHAR(7) NOT NULL, 105 | payment_date DATE NOT NULL, 106 | Payment_type VARCHAR(10) NOT NULL, 107 | Customer_id VARCHAR(6) NOT NULL, 108 | Cart_id VARCHAR(7) NOT NULL, 109 | PRIMARY KEY (payment_id), 110 | FOREIGN KEY (Customer_id) REFERENCES Customer(Customer_id), 111 | FOREIGN KEY (Cart_id) REFERENCES Cart(Cart_id), 112 | total_amount numeric(6) 113 | ); 114 | 115 | CREATE TABLE Product 116 | ( 117 | Product_id VARCHAR(7) NOT NULL, 118 | Type VARCHAR(7) NOT NULL, 119 | Color VARCHAR(15) NOT NULL, 120 | P_Size VARCHAR(2) NOT NULL, 121 | Gender CHAR(1) NOT NULL, 122 | Commission NUMBER(2) NOT NULL, 123 | Cost NUMBER(5) NOT NULL, 124 | Quantity NUMBER(2) NOT NULL, 125 | Seller_id VARCHAR(6), 126 | PRIMARY KEY (Product_id), 127 | FOREIGN KEY (Seller_id) REFERENCES Seller(Seller_id) 128 | ON DELETE SET NULL 129 | ); 130 | 131 | CREATE TABLE Cart_item 132 | ( 133 | Quantity_wished NUMBER(1) NOT NULL, 134 | Date_Added DATE NOT NULL, 135 | Cart_id VARCHAR(7) NOT NULL, 136 | Product_id VARCHAR(7) NOT NULL, 137 | FOREIGN KEY (Cart_id) REFERENCES Cart(Cart_id), 138 | FOREIGN KEY (Product_id) REFERENCES Product(Product_id), 139 | Primary key(Cart_id,Product_id) 140 | ); 141 | 142 | alter table Cart_item add purchased varchar(3) default 'NO'; 143 | ``` 144 | 145 | ### 3.2 Inserting Values 146 | 147 | These are some demo values. Full data will be updated in future commits 148 | 149 | ```sql 150 | insert into Cart values('crt1011'); 151 | 152 | insert into Customer values('cid100','ABCM1235','rajat','G-453','632014',9893135876, 'crt1011'); 153 | 154 | insert into Seller values('sid100','12345','aman','delhi cmc'); 155 | 156 | insert into Product values('pid1001','jeans','red','32','M',10,10005,20,'sid100'); 157 | 158 | insert into Seller_Phone_num values('9943336206','sid100'); 159 | 160 | insert into Cart_item values(3,to_date('10-OCT-1999','dd-mon-yyyy'),'crt1011','pid1001','Y'); 161 | 162 | insert into Payment values('pmt1001',to_date('10-OCT-1999','dd-mon-yyyy'),'online','cid100','crt1011',NULL); 163 | ``` 164 | 165 | ## 4. Queries 166 | 167 | ### 4.1 Basic Queries 168 | 169 | #### If the customer wants to see details of product present in the cart 170 | 171 | ```sql 172 | select * from product where product_id in( 173 | select product_id from Cart_item where (Cart_id in ( 174 | select Cart_id from Customer where Customer_id='cid100' 175 | )) 176 | and purchased='NO'); 177 | ``` 178 | 179 | #### If a customer wants to see order history 180 | 181 | ```sql 182 | select product_id,Quantity_wished from Cart_item where (purchased='Y' and Cart_id in (select Cart_id from customer where Customer_id='cid101')); 183 | ``` 184 | 185 | #### Customer wants to see filtered products on the basis of size,gender,type 186 | 187 | ```sql 188 | select product_id, color, cost, seller_id from product where (type='jeans' and p_size='32' and gender='F' and quantity>0) 189 | ``` 190 | 191 | #### If customer wants to modify the cart 192 | 193 | ```sql 194 | delete from cart_item where (product_id='pid1001' and Cart_id in (select cart_id from Customer where Customer_id='cid100')); 195 | ``` 196 | 197 | #### If a seller stops selling his product 198 | 199 | ```sql 200 | delete from seller where seller_id = 'sid100'; 201 | update product set quantity = 00 where seller_id is NULL; 202 | ``` 203 | 204 | #### If admin want to see what are the product purchased on the particular date 205 | 206 | ```sql 207 | select product_id from cart_item where (purchased='Y' and date_added='12-dec-2018'); 208 | ``` 209 | #### How much product sold on the particular date 210 | 211 | ```sql 212 | select count(product_id) count_pid,date_added from Cart_item where purchased='Y' group by(date_added); 213 | ``` 214 | #### If a customer want to know the total price present in the cart 215 | 216 | ```sql 217 | select sum(quantity_wished * cost) total_payable from product p join cart_item c on p.product_id=c.product_id where c.product_id in (select product_id from cart_item where cart_id in(select Cart_id from customer where customer_id='cid101') and purchased=’Y’); 218 | ``` 219 | #### Show the details of the customer who has not purchased any thing 220 | 221 | ```sql 222 | Select * from customer where customer_id not in (select customer_id from Payment); 223 | ``` 224 | #### Find total profit of the website from sales. 225 | 226 | ```sql 227 | select sum(quantity_wished * cost * commission/100) total_profit from product p join cart_item c on p.product_id=c.product_id where purchased=’Y’; 228 | ``` 229 | 230 | ### 4.2 PL/SQL function 231 | #### Procedure which returns the type of product with the cost less than the given cost 232 | 233 | ```sql 234 | create or replace procedure cost_filter(c in number,t in varchar) 235 | is 236 | cs product.cost%type; 237 | ty product.type%type; 238 | id product.product_id%type; 239 | cursor cf is 240 | select product_id,cost,type from product where cost0 then 322 | dbms_output.put_line('Sorry'); 323 | end if; 324 | insert into cart values(c); 325 | end; 326 | ``` 327 | #### Trigger to update the total amount of user everytime he adds something to payment table 328 | ```sql 329 | create or replace function total_cost(cId in varchar) 330 | return number 331 | is 332 | total number(2) :=0; 333 | begin 334 | select sum(cost) into total from product,cart_item where product.product_id=cart_item.product_id and cart_id=cId; 335 | return total; 336 | end; 337 | 338 | create or replace trigger before_pay_up 339 | before insert 340 | on 341 | payment 342 | for each row 343 | declare 344 | total number(3); 345 | begin 346 | total :=total_cost(:new.cart_id); 347 | insert into payment values(:new.payment_id,:new.payment_date,:new.payment_type,:new.customer_id,:new.cart_id,total); 348 | end; 349 | ``` 350 | ## Contributors 351 | Do check the contributors to follow some awesome projects 352 | 353 | - [@bhumijgupta](https://www.github.com/bhumijgupta) 354 | - [@YashMeh](https://www.github.com/YashMeh) 355 | - [@roney_b](https://www.github.com) 356 | 357 | > Feel free to fork the repository and contribute to this project. 358 | You made it till the end. Brofist :punch:!!! 359 | -------------------------------------------------------------------------------- /images/new_er.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhumijgupta/Ecommerce-management-DBMS-project/60446766daaaec5706218f9e98de760c69bbe720/images/new_er.png -------------------------------------------------------------------------------- /images/new_relational.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhumijgupta/Ecommerce-management-DBMS-project/60446766daaaec5706218f9e98de760c69bbe720/images/new_relational.png --------------------------------------------------------------------------------