-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_schema.sql
More file actions
126 lines (100 loc) · 3.22 KB
/
create_schema.sql
File metadata and controls
126 lines (100 loc) · 3.22 KB
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
drop database eshopping;
create database eshopping;
use eshopping;
create table customer(
id int NOT NULL AUTO_INCREMENT,
username varchar(60) not null,
password varchar(60) not null,
email varchar(60) not null,
address varchar(60) not null,
cart_id int null,
constraint pk_customer primary key(id)
);
create table address(
id int not null,
customer_id int not null,
city varchar(60) not null,
state varchar(60) not null,
pincode varchar(60) not null,
constraint pk_address primary key(id),
constraint fk_customer_id foreign key (customer_id) references customer(id)
);
create table cart(
id int ,
customer_id int not null,
empty bit not null,
constraint pk_cart primary key(id),
constraint fk_customer_cart foreign key (customer_id) references customer(id)
);
alter table customer add constraint fk_cart foreign key (cart_id) references cart(id);
create table payment_detail(
payment_detail_id int AUTO_INCREMENT,
customer_detail int,
card_number varchar(255) NOT NULL,
card_expiry_date date NOT NULL,
bank_name varchar(255)NOT NULL,
constraint pk_payment_detail PRIMARY KEY (payment_detail_id),
constraint FOREIGN KEY (customer_detail) REFERENCES customer(id)
);
create table customer_order(
order_id int AUTO_INCREMENT,
customer_detail int,
placed_date date NOT NULL,
status varchar(255),
total_amount int,
constraint pk_customer_order PRIMARY KEY (order_id),
constraint FOREIGN KEY (customer_detail) REFERENCES customer(id)
);
create table product(
product_id int not null auto_increment,
description varchar(255) not null,
price int not null,
images varchar(255),
constraint pk_product_id primary key(product_id)
);
create table order_item(
order_item_id int AUTO_INCREMENT,
order_detail int,
quantity int,
sub_amount int,
product_detail int,
constraint pk_order_item PRIMARY KEY (order_item_id),
constraint foreign key (product_detail) references product(product_id),
constraint FOREIGN KEY (order_detail) REFERENCES customer_order(order_id)
);
create table feedback(
feedback_id int AUTO_INCREMENT,
customer_detail int not null,
product_detail int,
description varchar(60),
rating int(5) NOT NULL,
images varchar(255),
constraint pk_feedback PRIMARY KEY (feedback_id),
constraint FOREIGN KEY (customer_detail) REFERENCES customer(id),
constraint FOREIGN KEY (product_detail) REFERENCES product(product_id) ON DELETE CASCADE
);
create table vendor(
vendor_id int AUTO_INCREMENT,
name varchar(255) NOT NULL,
details varchar(255)NOT NULL,
rating int(5) NOT NULL,
constraint pk_vendor PRIMARY KEY (vendor_id)
);
create table vendor_product(
vendor_product_id int AUTO_INCREMENT,
vendor_detail int,
product_detail int,
constraint pk_vendor_product PRIMARY KEY (vendor_product_id),
constraint FOREIGN KEY (product_detail) REFERENCES product(product_id),
constraint FOREIGN KEY (vendor_detail) REFERENCES vendor(vendor_id)
);
create table cart_item(
cart_item_id int AUTO_INCREMENT,
cart_detail int,
quantity int,
sub_amount int,
product_detail int,
constraint pk_cart_item PRIMARY KEY (cart_item_id),
constraint FOREIGN KEY (cart_detail) REFERENCES cart(id),
constraint foreign key (product_detail) references product(product_id)
);