-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.sql
168 lines (150 loc) · 4.24 KB
/
t.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
create table address (
AddID int not null auto_increment,
Street varchar(200) not null,
City varchar(100) not null,
State varchar(100) not null,
ZipCode varchar(6) not null, --check??
CID int,
primary key(AddID)
);
alter table address add foreign key(CID) references customer(CID);
alter table address auto_increment=500;
create table customer (
CID int not null auto_increment,
CName varchar(100) not null,
CGender boolean,
CDOB date,
CEmail varchar(100) not null,
CPass varchar(100) not null,
CMobileNo varchar(15),
BillingAddID int,
DeliveryAddID int,
check(CDOB<now() and ((year(now()) - year(CDOB)) < 120) and CMobileNo>=1000000000 and CMobileNo < 10000000000),
primary key(CID),
foreign key(BillingAddID) references address(AddID),
foreign key(DeliveryAddID) references address(AddID),
unique(CEmail)
);
alter table customer auto_increment=100;
create table product(
PID int not null auto_increment,
PName varchar(200) not null,
PDesc varchar(5000),
PPrice float not null,
PImgSrc varchar(500),
PStock int not null,
primary key(PID),
check(PPrice>0.0 and PStock>0)
);
alter table product auto_increment=200;
create table basket (
BID int not null auto_increment,
CID int,
NumProds int,
TotalCost float not null,
primary key(BID),
foreign key(CID) references customer(CID),
check(NumProds>=0 and TotalCost>=0.0),
unique(CID)
);
alter table basket auto_increment=300;
create table basketProds (
BID int,
PID int,
Quantity int not null,
foreign key(BID) references basket(BID),
foreign key(PID) references product(PID),
primary key(BID,PID),
check(Quantity>0)
);
create table rating (
CID int,
PID int,
Value int not null,
check(Value>=0 and Value<=10),
foreign key(CID) references customer(CID)
foreign key(PID) references product(PID),
primary key(CID, PID)
);
create table comment (
CommID int not null auto_increment,
CID int,
PID int,
Comment varchar(500) not null,
primary key(CommID),
foreign key(CID) references customer(CID),
foreign key(PID) references product(PID)
);
alter table comment auto_increment=400;
create table tag (
TagID int not null auto_increment,
TagName varchar(100) not null,
unique(TagName),
);
alter table category auto_increment=700;
create table tagProduct (
PID int,
Tagtt,
foreign key(PID) references product(PID),
foreign key(TagID) references tag(TagID),
unique(PID,TagID)
);
create table ordr (
OrderID int not null auto_increment,
CID int,
PurchaseDate date not null,
PaymentMode varchar(20),
OrderStatus varchar(20) not null,
primary key(OrderID),
foreign key(CID) references customer(CID),
check(PurchaseDate<now() and (year(PurchaseDate)>1980))
)
alter table ordr auto_increment=600;
create table orderedProduct (
OrderID int,
PID int,
Quatity int not null,
primary key(OrderID,PID),
foreign key(OrderID) references ordr(OrderID),
foreign key(PID) references product(PID),
check(Quatity>0)
);
insert into customer(CName, CGender, CDOB, CEmail, CPass, CMobileNo, BillingAddID, DeliveryAddID) values
('Akhilesh', 'M', '1994-09-04', 'akhilesh_alliswell@yahoo.com', 'abcd', 9911052855, 500,500),
('Mayank', 'M', '1994-09-05', 'mayankjain94@yahoo.com', 'adbc', 9845632157, 501, 501),
('Aman', 'M', '1992-01-01', 'aman1123@gmail.com', 'pqrs', 9711881372, 502,502),
('Akhil', 'M', '1993-10-10', 'akhilnsit12@gmail.com', 'wxyz', 9874563210, 503, 503),
('Anmol', 'M', '1994-01-01', 'anmolchugh19@yahoo.in', 'asdf', 9658742310, 504, 504),
('Jack Reacher', 'M', '03/23/1978', 'jackreacher123@gmail.com', 'Reacher123', 7823823873, 505, 505),
('Toby Mcguire', 'M', '07/29/1972', 'tobyMcguire297@gmail.com', 'Eureka', 7859375233, 506, 506);
insert into address(Street, City, State) values
('Khans, St. Joseph’s Road', 'Bannimantap', 'Haryana'),
('CFTRI House', 'CFTRI', 'Delhi'),
('Vanarpet', 'Viveknagar', 'Bihar'),
('a-11, big door', 'Outhicamannii House', 'Kerala');
create table category (
CatID int not null auto_increment,
CatName varchar(100) not null,
CatImgSrc varchar(200),
ParentCatID int,
primary key(CatID),
unique(CatName)
);
insert into tag(TagName) values
('woodland'),
('footwear'),
('sandals'),
('sandal'),
('jackandjone'),
('jackandjones'),
('jack'),
('jones'),
('shoe'),
('shoes'),
('lacoste'),
('formal'),
('titan'),
('watch'),
('gforce'),
('casual'),
('formal');