-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApniDukan-schema.sql
145 lines (133 loc) · 3.58 KB
/
ApniDukan-schema.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
DROP DATABASE IF EXISTS ApniDukan;
CREATE DATABASE ApniDukan;
USE ApniDukan;
CREATE TABLE Admin (
admin_ID INT,
admin_fname VARCHAR(30),
admin_lname VARCHAR(30),
admin_email VARCHAR(30),
admin_password VARCHAR(30),
PRIMARY KEY (admin_ID)
);
CREATE TABLE Category (
category_ID INT,
category_name VARCHAR(30),
PRIMARY KEY (category_ID)
);
CREATE TABLE Product (
product_ID INT,
product_name VARCHAR(50),
product_price FLOAT,
product_description VARCHAR(100),
product_brand VARCHAR(30),
product_image VARCHAR(50),
product_rating FLOAT,
product_available_quantity INT,
admin_ID INT,
category_ID INT,
PRIMARY KEY (product_ID),
FOREIGN KEY (admin_ID)
REFERENCES Admin (admin_ID)
ON DELETE CASCADE,
FOREIGN KEY (category_ID)
REFERENCES Category (category_ID)
ON DELETE SET NULL,
CONSTRAINT rating_check CHECK (product_rating <= 5)
);
CREATE TABLE Cart (
cart_ID INT,
cart_amount FLOAT,
PRIMARY KEY (cart_ID)
);
CREATE TABLE Cart_contents (
cart_ID INT,
product_ID INT,
product_quantity INT,
PRIMARY KEY (cart_ID , product_ID),
FOREIGN KEY (cart_ID)
REFERENCES Cart (cart_ID)
ON DELETE CASCADE,
FOREIGN KEY (product_ID)
REFERENCES Product (product_ID)
ON DELETE CASCADE
-- UNIQUE INDEX unique_carts (cart_ID)
);
CREATE TABLE Customer (
customer_ID INT,
customer_fname VARCHAR(30),
customer_lname VARCHAR(30),
customer_email VARCHAR(30),
customer_password VARCHAR(30),
customer_balance INT,
customer_dob DATE,
customer_address_house_no VARCHAR(30),
customer_address_city VARCHAR(30),
customer_address_state VARCHAR(30),
customer_address_pincode VARCHAR(6),
cart_ID INT,
PRIMARY KEY (customer_ID),
FOREIGN KEY (cart_ID)
REFERENCES Cart (cart_ID)
ON DELETE SET NULL
);
CREATE TABLE Customer_phone (
customer_ID INT,
customer_phone VARCHAR(13),
PRIMARY KEY (customer_ID , customer_phone),
FOREIGN KEY (customer_ID)
REFERENCES Customer (customer_ID)
ON DELETE CASCADE
);
CREATE TABLE Orders (
order_ID INT,
order_amount FLOAT,
order_date DATE,
order_status VARCHAR(30),
order_billing_address_house_no VARCHAR(30),
order_billing_address_city VARCHAR(30),
order_billing_address_state VARCHAR(30),
order_billing_address_pincode VARCHAR(6),
PRIMARY KEY (order_ID)
);
CREATE TABLE Order_contents (
order_ID INT,
product_ID INT,
product_quantity INT,
PRIMARY KEY (order_ID , product_ID),
FOREIGN KEY (order_ID)
REFERENCES Orders (order_ID)
ON DELETE CASCADE,
FOREIGN KEY (product_ID)
REFERENCES Product (product_ID)
ON DELETE CASCADE
);
CREATE TABLE Payment (
order_ID INT,
customer_ID INT NOT NULL,
payment_ID INT,
payment_amount FLOAT,
payment_date DATE,
payment_status VARCHAR(30),
PRIMARY KEY (order_ID),
FOREIGN KEY (order_ID)
REFERENCES Orders (order_ID)
ON DELETE CASCADE,
FOREIGN KEY (customer_ID)
REFERENCES Customer (customer_ID)
ON DELETE CASCADE
);
CREATE TABLE Delivery (
delivery_ID INT,
delivery_date DATE,
delivery_status VARCHAR(30),
delivery_address_house_no VARCHAR(30),
delivery_address_city VARCHAR(30),
delivery_address_state VARCHAR(30),
delivery_address_pincode VARCHAR(6),
order_ID INT,
PRIMARY KEY (delivery_ID),
FOREIGN KEY (order_ID)
REFERENCES Orders (order_ID)
ON DELETE CASCADE
-- UNIQUE INDEX unique_orders (order_ID)
);