-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueries.sql
120 lines (107 loc) · 3.61 KB
/
queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
CREATE TABLE seller_table (
seller_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
seller_name VARCHAR(100) NOT NULL,
seller_email VARCHAR(50) NOT NULL UNIQUE,
seller_pass VARCHAR(100) NOT NULL,
seller_reg_date DATETIME NOT NULL,
seller_edit_date DATETIME NOT NULL,
seller_bank_name VARCHAR(100) NOT NULL,
seller_account_number BIGINT NOT NULL,
seller_mob_no VARCHAR(20),
seller_address VARCHAR(200),
seller_firm_name VARCHAR(100) NOT NULL UNIQUE,
seller_firm_address VARCHAR(200),
seller_profile_pic VARCHAR(100),
seller_firm_info VARCHAR(200)
);
CREATE TABLE customer_table (
customer_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
customer_name VARCHAR(100) NOT NULL,
customer_email VARCHAR(50) NOT NULL UNIQUE,
customer_pass VARCHAR(100) NOT NULL,
customer_reg_date DATETIME NOT NULL,
customer_edit_date DATETIME NOT NULL,
customer_bank_name VARCHAR(50),
customer_account_number BIGINT,
customer_mob_no VARCHAR(20),
customer_address VARCHAR(200)
);
CREATE TABLE product_table (
product_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
product_category VARCHAR(45) NOT NULL,
product_name VARCHAR(100) NOT NULL,
product_about VARCHAR(200),
product_pic VARCHAR(100) NOT NULL,
product_price BIGINT NOT NULL,
product_rating_count INT,
product_best_rating INT,
product_max_price BIGINT NOT NULL,
product_seller_id INT NOT NULL,
product_count_stock BIGINT NOT NULL,
product_reg_date DATETIME NOT NULL,
product_update_date DATETIME NOT NULL,
FOREIGN KEY (product_seller_id) REFERENCES seller_table(seller_id) ON DELETE CASCADE
);
CREATE TABLE cart_table (
-- cart_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
cart_product_id INT,
cart_product_price BIGINT NOT NULL,
cart_modified DATETIME NOT NULL,
cart_product_count BIGINT NOT NULL,
cart_purchased BOOLEAN NOT NULL,
cart_product_total BIGINT NOT NULL,
cart_customer_id INT,
FOREIGN KEY (cart_product_id) REFERENCES product_table(product_id) ON DELETE
SET
NULL,
FOREIGN KEY (cart_customer_id) REFERENCES customer_table(customer_id) ON DELETE CASCADE
);
CREATE TABLE transaction_table (
transc_id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
transc_date DATETIME NOT NULL,
transc_product_id INT,
transc_total_price BIGINT NOT NULL,
-- transc_cart_id INT NOT NULL,
transc_seller_id INT,
transc_customer_id INT,
transc_invoice_number VARCHAR(20) NOT NULL,
transc_shipping_address varchar(200) NOT NULL,
FOREIGN KEY (transc_product_id) REFERENCES product_table(product_id) ON DELETE
SET
NULL,
FOREIGN KEY (transc_seller_id) REFERENCES seller_table(seller_id) ON DELETE
SET
NULL,
FOREIGN KEY (transc_customer_id) REFERENCES customer_table(customer_id) ON DELETE
SET
NULL
);
DELIMITER $$
CREATE
TRIGGER customer_product_purchased AFTER INSERT
ON transaction_table
FOR EACH ROW
BEGIN
UPDATE cart_table SET
cart_purchased = true
WHERE cart_customer_id = NEW.transc_customer_id AND
cart_product_id = NEW.transc_product_id;
END $$
DELIMITER ;
-- DELETE TRIGGER CODE
-- DELIMITER $$
-- CREATE
-- TRIGGER customer_product_purchased AFTER INSERT
-- ON transaction_table
-- FOR EACH ROW
-- BEGIN
-- DELETE FROM cart_table
-- WHERE cart_customer_id = NEW.transc_customer_id AND
-- cart_product_id = NEW.transc_product_id;
-- END $$
-- DELIMITER ;
-- TO DELETE THE TRIGGER FROM TABLE
-- DELIMITER $$
-- USE `e-commerce`$$
-- DROP TRIGGER IF EXISTS `e-commerce`.`customer_product_purchased` $$
-- DELIMITER ;