Project 1
Customer Table :
CREATE TABLE c u s → m e r ">cus→mercus→mer (
)
ALTER TABLE c u s → m e r ">cus→mercus→mer
ADD PRIMARY KEY (C u s → m e r i d ">Cus→meridCus→merid),
ADD KEY C a r t i d ">CartidCartid (C a r t i d ">CartidCartid);
ALTER TABLE c u s → m e r ">cus→mercus→mer
ADD CONSTRAINT c u s → m e r i b f k 1 ">cus→meribfk1cus→meribfk1 FOREIGN KEY (C a r t i d ">CartidCartid) REFERENCES c a r t ">cartcart (C a r t i d ">CartidCartid);
INSERT INTO c u s → m e r ">cus→mercus→mer (C u s → m e r i d ">Cus→meridCus→merid, N a m e ">NameName, e m a i l ">emailemail, ≥ n d e r ">≥nder≥nder, d o b ">dobdob, c i t y ">citycity, ∂ i v e r y A d d r e s s ">∂iveryAddress∂iveryAddress, c o n t a c t ">contactcontact, C u r r e n t or d e r ">CurrentorderCurrentorder, P r e v O r d e r ">PrevOrderPrevOrder, C a r t i d ">CartidCartid) VALUES
('0023pkr', 'Aishwarya', '[email protected]', 'female', '2003-11-14 15:23:33', 'mumbai', 'dadar', 888859944, 'Dress', 'lehanga', 'c_105'),
('B12kr', 'Abhi', '[email protected]', 'male', '1995-11-02 15:19:36', 'Bangalore', 'bangalore', 988849445, 'Headphone', 'Shirts', 'c_103'),
('G_235', 'Ganesh', '[email protected]', 'male', '2022-11-05 08:11:53', 'Pune', 'Hadapsar Pune', 456777653, 'T_Shirt', 'Cap', 'c_102'),
('Tj402', 'Vankatesh', 'vanki@[email protected]', 'male', '2002-11-21 15:19:36', 'Chennai', 'chennai', 78906483, 'Homethreater', 'sounds', 'c_104'),
('V_Patil', 'Vaibhav', '[email protected]', 'Male', '2000-11-12 12:41:53', 'Nanded', 'Latur', 845905668, 'Macbook', 'HP Laptop', 'c_101');
Cart Table :
CREATE TABLE c a r t ">cartcart (
);
ALTER TABLE c a r t ">cartcart
ADD PRIMARY KEY (C a r t i d ">CartidCartid);
INSERT INTO c a r t ">cartcart (C a r t i d ">CartidCartid, I t e m q u a n t i t y ">ItemquantityItemquantity, T o t a l cos t ">TotalcostTotalcost) VALUES
('c_101', 20, 3000),
('c_102', 10, 1200),
('c_103', 2, 200),
('c_104', 5, 2000),
('c_105', 10, 70000);
Cart_Item Table :
CREATE TABLE c a r t i t e m ">cartitemcartitem (
);
ALTER TABLE c a r t i t e m ">cartitemcartitem
ADD PRIMARY KEY (C a r t i d ">CartidCartid,P r o d u c t i d ">ProductidProductid),
ADD KEY P r o d u c t i d ">ProductidProductid (P r o d u c t i d ">ProductidProductid);
ALTER TABLE c a r t i t e m ">cartitemcartitem
ADD CONSTRAINT c a r t i t e m i b f k 1 ">cartitemibfk1cartitemibfk1 FOREIGN KEY (C a r t i d ">CartidCartid) REFERENCES c a r t ">cartcart (C a r t i d ">CartidCartid),
ADD CONSTRAINT c a r t i t e m i b f k 2 ">cartitemibfk2cartitemibfk2 FOREIGN KEY (P r o d u c t i d ">ProductidProductid) REFERENCES ∏ u c t ">∏uct∏uct (P r o d u c t i d ">ProductidProductid),
ADD CONSTRAINT c a r t i t e m i b f k 3 ">cartitemibfk3cartitemibfk3 FOREIGN KEY (C a r t i d ">CartidCartid) REFERENCES c a r t ">cartcart (C a r t i d ">CartidCartid);
INSERT INTO c a r t i t e m ">cartitemcartitem (C a r t i d ">CartidCartid, P r o d u c t i d ">ProductidProductid, D a t e A d d e d ">DateAddedDateAdded, p u r c h a s e d ">purchasedpurchased, i t e m q u a n t i t y ">itemquantityitemquantity) VALUES
('c_101', 'P_3', '2022-11-07', 'NO', 7),
('c_102', 'P_1', '2022-11-22', 'y', 3),
('c_103', 'P_1', '2022-10-19', 'Y', 5),
('c_104', 'P_3', '2022-11-03', 'Y', 6),
('c_105', 'P_1', '2022-11-01', 'NO', 3);
Category Table :
CREATE TABLE c a t e g or y ">categorycategory (
);
ALTER TABLE c a t e g or y ">categorycategory
ADD PRIMARY KEY (c a t e g or y i d ">categoryidcategoryid),
ADD KEY P r o d u c t i d ">ProductidProductid (P r o d u c t i d ">ProductidProductid);
ALTER TABLE c a t e g or y ">categorycategory
ADD CONSTRAINT c a t e g or y i b f k 1 ">categoryibfk1categoryibfk1 FOREIGN KEY (P r o d u c t i d ">ProductidProductid) REFERENCES ∏ u c t ">∏uct∏uct (P r o d u c t i d ">ProductidProductid);
INSERT INTO c a t e g or y ">categorycategory (c a t e g or y i d ">categoryidcategoryid, c a t e g or y n a m e ">categorynamecategoryname, P r o d u c t i d ">ProductidProductid, ⊂ C a t e g or y ">⊂Category⊂Category) VALUES
('cat_285', 'Accessories', 'P_1', 'Headphones'),
('cat_288', 'Laptops', 'P_1', 'Apple'),
('cat_291', 'Accessories', 'P_3', 'Phones'),
('cat_299', 'Phones', 'P_3', 'Vivo'),
('cat_301', 'Fashion', 'P_3', 'Mens');
Orders Table :
CREATE TABLE or d e r s ">ordersorders (
);
ALTER TABLE or d e r s ">ordersorders
ADD PRIMARY KEY (or d e r i d ">orderidorderid),
ADD KEY c u s → m e r i d ">cus→meridcus→merid (c u s → m e r i d ">cus→meridcus→merid);
ALTER TABLE or d e r s ">ordersorders
ADD CONSTRAINT or d e r s i b f k 1 ">ordersibfk1ordersibfk1 FOREIGN KEY (c u s → m e r i d ">cus→meridcus→merid) REFERENCES c u s → m e r ">cus→mercus→mer (C u s → m e r i d ">Cus→meridCus→merid);
INSERT INTO or d e r s ">ordersorders (or d e r i d ">orderidorderid, s t a t u s ">statusstatus, or d e r d a t e ">orderdateorderdate, ∂ i v e r y d a t e ">∂iverydate∂iverydate, c u s → m e r i d ">cus→meridcus→merid) VALUES
('02341mrk', 'shipping', '2022-11-05', '2022-11-08', 'V_Patil'),
('09hjwe3', 'delivered', '2022-11-01', '2022-11-05', '0023pkr'),
('1567o3d', 'delivered', '2022-11-02', '2022-11-04', 'G_235'),
('klr892', 'dileverd soon', '2022-11-04', '2022-11-06', 'B12kr'),
('ormh26', 'shiiping', '2022-11-02', '2022-11-07', 'Tj402');
Payment Table :
CREATE TABLE p a y m e n t ">paymentpayment (
);
ALTER TABLE p a y m e n t ">paymentpayment
ADD PRIMARY KEY (p a y m e n t i d ">paymentidpaymentid),
ADD KEY C u s → m e r i d ">Cus→meridCus→merid (C u s → m e r i d ">Cus→meridCus→merid),
ADD KEY C a r t i d ">CartidCartid (C a r t i d ">CartidCartid);
ALTER TABLE p a y m e n t ">paymentpayment
ADD CONSTRAINT p a y m e n t i b f k 1 ">paymentibfk1paymentibfk1 FOREIGN KEY (C u s → m e r i d ">Cus→meridCus→merid) REFERENCES c u s → m e r ">cus→mercus→mer (C u s → m e r i d ">Cus→meridCus→merid),
ADD CONSTRAINT p a y m e n t i b f k 2 ">paymentibfk2paymentibfk2 FOREIGN KEY (C a r t i d ">CartidCartid) REFERENCES c a r t ">cartcart (C a r t i d ">CartidCartid);
INSERT INTO p a y m e n t ">paymentpayment (p a y m e n t i d ">paymentidpaymentid, p a y m e n t d a t e ">paymentdatepaymentdate, P a y m e n t t y p e ">PaymenttypePaymenttype, C u s → m e r i d ">Cus→meridCus→merid, C a r t i d ">CartidCartid) VALUES
('0023449', '2022-11-03', 'reference-0394j34', 'B12kr', 'c_104'),
('0294738484', '2022-11-01', 'UPI', '0023pkr', 'c_102'),
('488443565', '2022-11-02', 'phonepay', 'G_235', 'c_103'),
('4930980', '2022-11-04', 'bharatPay', 'V_Patil', 'c_101'),
('9849344', '2022-11-04', 'upi', 'Tj402', 'c_104');
Product Table :
CREATE TABLE ∏ u c t ">∏uct∏uct (
);
ALTER TABLE ∏ u c t ">∏uct∏uct
ADD PRIMARY KEY (P r o d u c t i d ">ProductidProductid),
ADD KEY s e l ≤ r i d ">sel≤ridsel≤rid (s e l ≤ r i d ">sel≤ridsel≤rid);
ALTER TABLE ∏ u c t ">∏uct∏uct
ADD CONSTRAINT ∏ u c t i b f k 1 ">∏uctibfk1∏uctibfk1 FOREIGN KEY (s e l ≤ r i d ">sel≤ridsel≤rid) REFERENCES s e l ≤ r ">sel≤rsel≤r (s e l ≤ r i d ">sel≤ridsel≤rid);
INSERT INTO ∏ u c t ">∏uct∏uct (P r o d u c t i d ">ProductidProductid, N a m e ">NameName, ">, s e l ≤ r i d ">sel≤ridsel≤rid, s i z e ">sizesize, q u a n t i t y ">quantityquantity, cos t ">costcost, d i s c o u n t ">discountdiscount, p l a c e f or ∂ i v e r y ">placefor∂iveryplacefor∂ivery, i s F e a t u r e d ">isFeaturedisFeatured, r a t ∈ g ">rat∈grat∈g, r e v i e w s ">reviewsreviews, i s O n S c a ≤ ">isOnSca≤isOnSca≤, C a t e g or y i d ">CategoryidCategoryid, b r and ">brandbrand, d e s c r i p t i o n ">descriptiondescription, t a g s ">tagstags, r e l a t e d ∏ u c t ">related∏uctrelated∏uct) VALUES
('Hag3943r', 'Rebion Goggals', 'red-black', 'S123_KR', 0, 1, 2000, 300, 'Latur', 'yes', 5, 4, 'yes', 'cat_291', 'Rebion', 'sunlight glasses', 'goggles', 'yellow glasses'),
('krt455', 'T_Shirt', 'Yellow', 'S111_MH', 42, 2, 3000, 200, 'Nanded', '', 4, 8, 'yes', 'Fashion', 'being human', 'T_shirt with cap', '', 'being humans jeans'),
('P_1', 'Macbook', 'black', 'S123_KR', 14, 1, 120000, 7000, 'pune', 'yes', 5, 40, 'very good product', 'C_301', 'Apple', 'Product is very branded and good', 'Laptop', 'IPad'),
('P_3', 'Vivo_30', 'silver', 'S111_MH', 20, 2, 40000, 2000, 'Latur', 'Welll feat', 7, 20, 'well developed', 'Phones', 'Vivo', 'Very good phone camera 64 ram 8 gb', 'vivo', 'vivo-28'),
('P_490g', 'headphone', 'white', 'S111_MH', 0, 3, 700, 110, 'pune', 'yes', 5, 5, 'yes', 'cat_285', 'realme', 'white headphones', 'realme', 'realme ipods');
Seller Table :
CREATE TABLE s e l ≤ r ">sel≤rsel≤r (
);
ALTER TABLE s e l ≤ r ">sel≤rsel≤r
ADD PRIMARY KEY (s e l ≤ r i d ">sel≤ridsel≤rid);
INSERT INTO s e l ≤ r ">sel≤rsel≤r (s e l ≤ r i d ">sel≤ridsel≤rid, N a m e ">NameName, M o b i ≤ n o ">Mobi≤noMobi≤no, p a s s w or d ">passwordpassword, P r o d u c t C a t e g or y ">ProductCategoryProductCategory) VALUES
('er455k', 'Jully', 59545554, 'li9345n', 'Accessories'),
('kjhkj54', 'Danni', 345665656, 'ggj54t02', 'Laptop'),
('S-66jd', 'Javed', 483595847, 'ghd3435j', 'fashion'),
('S111_MH', 'Abhi', 8549505, 'V4590nd', 'Accessories'),
('S123_KR', 'Vinay', 84564865, '90hf3e', 'Phones');
Some Queries :
If customer wants to see details of present in cart.
select * from product where product_id in( select product_id from Cart_item where (Cart_id in ( select Cart_id from Customer where Customer_id='cid100' )) and purchased='NO');
If customer want to see history of orders.
select product_id,item_quantity from Cart_item where (purchased='Y' and Cart_id in (select Cart_id from customer where Customer_id='V_Patil'));
If customer want to see total price fir product in cart.
select sum(item_quantity * 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='V_Patil') );