You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.0 KiB
148 lines
5.0 KiB
drop database if exists grocery_db;
|
|
create database grocery_db;
|
|
use grocery_db;
|
|
|
|
-- Product-Categories Table Schema
|
|
CREATE TABLE IF NOT EXISTS `productcategories` (
|
|
`categoryid` int(11) NOT NULL AUTO_INCREMENT,
|
|
`categoryname` varchar(50) NOT NULL,
|
|
PRIMARY KEY (`categoryid`)
|
|
);
|
|
|
|
INSERT INTO `productcategories` (`categoryid`, `categoryname`) VALUES
|
|
(1, 'Snacks'),
|
|
(2, 'Vegetables'),
|
|
(3, 'Fruits'),
|
|
(4, 'Beverages'),
|
|
(5, 'Bakery Products'),
|
|
(6, 'Fist-Meat');
|
|
|
|
select * from productcategories;
|
|
|
|
-- Users Table Schema
|
|
CREATE TABLE `users` (
|
|
`userid` int(11) NOT NULL AUTO_INCREMENT,
|
|
`userfirstname` varchar(50) DEFAULT NULL,
|
|
`userlastname` varchar(50) DEFAULT NULL,
|
|
`useremail` varchar(50) DEFAULT NULL,
|
|
`userpassword` varchar(50) DEFAULT NULL,
|
|
`usercity` varchar(50) DEFAULT NULL,
|
|
`userstate` varchar(20) DEFAULT NULL,
|
|
`userzip` varchar(12) DEFAULT NULL,
|
|
`userphone` varchar(20) DEFAULT NULL,
|
|
`useraddress` varchar(100) DEFAULT NULL,
|
|
`useraddress2` varchar(50) DEFAULT NULL,
|
|
PRIMARY KEY (`userid`)
|
|
);
|
|
|
|
ALTER TABLE users AUTO_INCREMENT = 100;
|
|
|
|
insert into users values(
|
|
100, "Rajesh", "Kumar",
|
|
"shawn@mail.com", "shawn@mail.com",
|
|
"Chennai", "Tamil Nadu", "600040",
|
|
"5000500050", "Block B, Abirami Apartments",
|
|
"Anna Nagar"
|
|
);
|
|
insert into users values(
|
|
101, "Vignesh", "Shivan",
|
|
"vignesh@mail.com", "vignesh@mail.com",
|
|
"Chennai", "Tamil Nadu", "600030",
|
|
"5000500060", "Block A, Harmony Melody",
|
|
"Shenoy Nagar"
|
|
);
|
|
|
|
select * from users;
|
|
create table Product(
|
|
`productid` int(12) NOT NULL AUTO_INCREMENT,
|
|
`productname` varchar(100) NOT NULL,
|
|
`productprice` float NOT NULL,
|
|
`productimage` varchar(100) NOT NULL,
|
|
`productcategoryid` int(11) not NULL,
|
|
PRIMARY KEY (`productid`),
|
|
FOREIGN KEY (`productcategoryid`) REFERENCES productcategories(`categoryid`)
|
|
);
|
|
|
|
ALTER TABLE Product AUTO_INCREMENT = 1000;
|
|
|
|
-- Vegetables
|
|
insert into product values (1000, "Carrot", 55,
|
|
"https://www.bigbasket.com/media/uploads/p/l/10000271_13-fresho-carrot-ooty.jpg", 2);
|
|
insert into product values (1001, "Potato", 30,
|
|
"https://www.bigbasket.com/media/uploads/p/l/10000159_25-fresho-potato.jpg", 2);
|
|
insert into product values (1002, "Cauliflower", 60,
|
|
"https://www.bigbasket.com/media/uploads/p/l/10000074_19-fresho-cauliflower.jpg", 2);
|
|
-- Fruits
|
|
insert into product values (1003, "Orange", 65,
|
|
"https://www.bigbasket.com/media/uploads/p/l/20000910_12-fresho-orange-imported.jpg", 3);
|
|
insert into product values (1004, "Banana - Yelakki", 70,
|
|
"https://www.bigbasket.com/media/uploads/p/l/10000031_21-fresho-banana-yelakki.jpg", 3);
|
|
-- Snacks
|
|
insert into product values (1005, "Britannia Good Day Cashew Cookies", 90,
|
|
"https://www.bigbasket.com/media/uploads/p/l/40083744_5-britannia-good-day-cashew-cookies.jpg", 1);
|
|
insert into product values (1006, "Haldirams Namkeen - Bhujia Sev", 200,
|
|
"https://www.bigbasket.com/media/uploads/p/l/100022552_1-haldirams-namkeen-bhujia-sev.jpg", 1);
|
|
-- Fist-Meat
|
|
insert into product values (1007, "Eggs - Regular (12)", 76,
|
|
"https://www.bigbasket.com/media/uploads/p/l/40083744_5-britannia-good-day-cashew-cookies.jpg", 6);
|
|
|
|
select * from product;
|
|
|
|
-- Orders Table Schema
|
|
|
|
CREATE TABLE IF NOT EXISTS `orders` (
|
|
`userid` int(11) NOT NULL,
|
|
`orderid` int(11) NOT NULL AUTO_INCREMENT,
|
|
`productname` varchar(100) NOT NULL,
|
|
`productprice` float NOT NULL,
|
|
PRIMARY KEY (`orderid`),
|
|
FOREIGN KEY (`userid`) REFERENCES users(`userid`)
|
|
);
|
|
|
|
ALTER TABLE orders AUTO_INCREMENT = 1000;
|
|
|
|
-- insert into orders values(1000,1,12.5,'indra nagar','panchshill nagar','bhilai','c.g.','490025','india','7896545210',25.3,56.2,'g@gmail.com','2021-09-10','done','456');
|
|
-- insert into orders values(1001,1,12.5,'indra nagar','panchshill nagar','bhilai','c.g.','490025','india','7896545210',25.3,56.2,'g@gmail.com','2021-09-10','done','457');
|
|
|
|
SELECT * FROM orders;
|
|
|
|
-- Members Table Schema
|
|
create table `members`(
|
|
`userid` int(11) NOT NULL,
|
|
`memberid` int(11) not null AUTO_INCREMENT,
|
|
`membername` varchar(20) not null,
|
|
`memberdoornumber` int(4) not null,
|
|
`totalitems` int(3) not null default 0,
|
|
`memberphone` varchar(15) not null,
|
|
`membertotalamount` float not null default 0,
|
|
PRIMARY KEY (`memberid`),
|
|
FOREIGN KEY (`userid`) REFERENCES users(`userid`)
|
|
);
|
|
|
|
INSERT INTO members VALUES(100, 1, "Abhishek", 501,0,"1234512345", 0);
|
|
INSERT INTO members VALUES(100, 2, "Meera", 502,5,"12345234567", 1200);
|
|
INSERT INTO members VALUES(100, 3, "Shyam", 503,10,"1234598745", 800);
|
|
|
|
select * from members;
|
|
|
|
CREATE TABLE IF NOT EXISTS `cart`(
|
|
`cartid` int (12) not null AUTO_INCREMENT,
|
|
`productid` int(12) NOT NULL,
|
|
`userid` int(12) not null,
|
|
`productname` varchar(100) NOT NULL,
|
|
`productprice` float NOT NULL,
|
|
`productcategoryid` int(11) not NULL,
|
|
PRIMARY KEY (`cartid`),
|
|
FOREIGN KEY (`productid`) REFERENCES product(`productid`),
|
|
FOREIGN KEY (`userid`) REFERENCES users(`userid`)
|
|
);
|
|
|
|
select * from cart;
|
|
|
|
drop user if exists 'testuser';
|
|
|
|
|
|
CREATE USER 'testuser' IDENTIFIED BY 'Password123';
|
|
grant all privileges on grocery_db.* to 'testuser'@'%' with grant option;
|
|
|
|
FLUSH PRIVILEGES;
|