drop database if exists shopmeout;
create database shopmeout;
use shopmeout;
drop table if exists Customer_sign_in;
CREATE TABLE Customer_sign_in (
customer_ID INT (50) not null,
Name_customer varchar(255) not null,
Credit_card BIGINT(100) not null,
Password_cust TEXT(150) not null,
Email_cust TEXT(50) not null,
primary key (customer_ID)
);
insert into Customer_sign_in values( 19867889, 'Stefan Darescu', 9018783269173917, 'personalcomputer84', 'stefandarescu@gmail.com');
insert into Customer_sign_in values( 11958178, 'Mogens Hemming', 5090180120973782,'masadebiliard4', 'mogenshemming@yahoo.com');
insert into Customer_sign_in values( 52562523, 'Viggo Kristian', 9015908218093698,'asawece', 'viggokristian@gmail.com');
insert into Customer_sign_in values( 42515323, 'Asbjørn Hjalmar', 0198490128761903,'esrjgads', 'asbjornhjalmar@hotmail.com');
insert into Customer_sign_in values( 69723642, 'Rasmus Bjarne', 9180583647839793,'Sgsyhdfs', 'rasmusbjarne@outlook.com');
CREATE TABLE Products (
Product_id INT(150) not null,
Product_name VARCHAR(100) not null,
Product_price DECIMAL(6,2) not null,
Deduction_price INT(50) not null,
Deadline DATE not null,
PRIMARY KEY (Product_id)
);
insert into Products values( 509687, 'Plain Flower', 59.46, 10, '2013-05-30');
insert into Products values( 485901, 'Cow Milk', 17.85, 12, '2013-04-18');
insert into Products values( 908571, 'Kærgården', 131.75, 8, '2013-04-07');
insert into Products values( 432612, 'Chicken Eggs', 27.57, 9, '2013-03-31');
insert into Products values( 853235, 'Pepsi Cherry', 25.11, 12, '2013-03-25');
insert into Products values( 357342, 'Spaghetti', 10.8, 5, '2013-03-20');
insert into Products values( 123563, 'Spaghetti sos', 22.4, 10, '2013-03-17');
delimiter //
CREATE TRIGGER first_trigger BEFORE UPDATE ON Products
FOR EACH ROW
BEGIN
IF NEW.Product_price < 20 THEN
SET NEW.Product_price = 15;
ELSEIF NEW.Product_price > 140 THEN
SET NEW.Product_price = 80;
END IF;
END;//
delimiter ;
UPDATE Products set Product_price = 25 where Product_id = 509687;
UPDATE Products set Product_price = 22 where Product_id = 908571;
CREATE TABLE Recipes (
Recipes_id INT (10) not null,
Recipe_name CHAR (150) not null,
Recipe_descrip TEXT(255) not null,
primary key (Recipes_id)
);
insert into Recipes values( 513678, 'Pancakes', 'Crack the eggs into a blender, add the flour, milk and a pinch of sea salt, and blitz until smooth.');
insert into Recipes values( 867523, 'Spaghetti Bolognese', 'Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.');
CREATE TABLE Shopping_list (
Shopping_list_id INT (50) not null,
customer_ID INT (50) not null,
Items_quantity INT (50) not null,
primary key (Shopping_list_id),
foreign key (customer_ID)
REFERENCES
Customer_sign_in (customer_ID)
);
insert into Shopping_list values( 14081869, 19867889, 15);
insert into Shopping_list values( 15163266, 11958178, 30);
insert into Shopping_list values( 34232325, 52562523, 3);
insert into Shopping_list values( 82412845, 42515323, 7);
insert into Shopping_list values( 36272236, 69723642, 5);
CREATE TABLE Payment (
Payment_id INT(150) NOT NULL,
customer_ID INT(150) NOT NULL,
Date_pay DATETIME NOT NULL,
Shopping_list_id INT(50) NOT NULL,
PRIMARY KEY (Payment_id),
FOREIGN KEY (customer_ID)
REFERENCES Customer_sign_in (customer_ID),
FOREIGN KEY (Shopping_list_id)
REFERENCES Shopping_list (Shopping_list_id)
);
insert into Payment values( 84163801, 19867889, '2013-05-25 07:12:00', 14081869);
insert into Payment values( 89171750, 11958178, '2013-04-08 21:43:12', 15163266);
insert into Payment values( 19829247, 52562523, '2013-04-02 16:41:09', 34232325);
insert into Payment values( 35819204, 42515323, '2013-03-25 23:54:32', 82412845);
insert into Payment values( 25085739, 69723642, '2013-03-20 12:38:56', 36272236);
CREATE TABLE Has (
Product_id INT(150) NOT NULL,
Recipes_id INT(150) NOT NULL,
FOREIGN KEY (Product_id)
REFERENCES Products (Product_id),
FOREIGN KEY (Recipes_id)
REFERENCES Recipes (Recipes_id)
);
insert into Has values( 509687, 513678);
insert into Has values( 485901, 513678);
insert into Has values( 908571, 513678);
insert into Has values( 357342, 867523);
insert into Has values( 123563, 867523);
CREATE TABLE Goes (
Product_id INT(150) NOT NULL,
Shopping_list_id INT(150) NOT NULL,
FOREIGN KEY (Product_id)
REFERENCES Products (Product_id),
FOREIGN KEY (Shopping_list_id)
REFERENCES Shopping_list (Shopping_list_id)
);
insert into Goes values( 485901, 14081869);
insert into Goes values( 123563, 14081869);
insert into Goes values( 908571, 14081869);
insert into Goes values( 485901, 82412845);
insert into Goes values( 123563, 34232325);
insert into Goes values( 357342, 34232325);
select * from Shopping_list;
select * from Payment;
select * from Customer_sign_in;
select * from Recipes;
select * from Products;
select * from Has;
select * from Goes;
SELECT c.customer_ID, p.Product_id, p.Product_price, s.Items_quantity,
(p.Product_price * s.Items_quantity) AS total FROM Products p LEFT JOIN Shopping_list s ON p.Product_id = s.Product_id LEFT JOIN Customer_sign_in c ON c.customer_ID = s.customer_ID;