-
Notifications
You must be signed in to change notification settings - Fork 2
/
Beacon_init.sql
executable file
·305 lines (245 loc) · 9.45 KB
/
Beacon_init.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- 主机: database
-- 生成日期: 2020-07-25 07:15:59
-- 服务器版本: 8.0.20
-- PHP 版本: 7.4.6
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- 数据库: `Beacon`
--
-- --------------------------------------------------------
--
-- 表的结构 `Requests`
--
CREATE TABLE `Requests` (
`RequestId` int NOT NULL,
`BuyerId` varchar(50) DEFAULT NULL,
`ProductName` varchar(50) DEFAULT NULL,
`Tag` varchar(50) DEFAULT NULL,
`Description` varchar(500) DEFAULT NULL,
`Image` varchar(100) DEFAULT NULL,
`IntendedPrice` double DEFAULT NULL,
`SaleId` int DEFAULT NULL,
`DatePost` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 表的结构 `Sales`
--
CREATE TABLE `Sales` (
`SaleId` int NOT NULL,
`SellerId` varchar(50) DEFAULT NULL,
`ProductName` varchar(50) DEFAULT NULL,
`Tag` varchar(50) DEFAULT NULL,
`Description` varchar(500) DEFAULT NULL,
`Image` varchar(100) DEFAULT NULL,
`IntendedPrice` double DEFAULT NULL,
`OriginalPrice` double DEFAULT NULL,
`Depreciation` int DEFAULT NULL,
`IntendedBuyerId` varchar(50) DEFAULT NULL,
`DatePost` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 替换视图以便查看 `SRT_leftJoin`
-- (参见下面的实际视图)
--
CREATE TABLE `SRT_leftJoin` (
`Tag` varchar(50)
,`cntSales` bigint
,`cntRequests` bigint
,`cntTrans` bigint
);
-- --------------------------------------------------------
--
-- 替换视图以便查看 `SRT_rightJoin`
-- (参见下面的实际视图)
--
CREATE TABLE `SRT_rightJoin` (
`Tag` varchar(50)
,`cntSales` bigint
,`cntRequests` bigint
,`cntTrans` bigint
);
-- --------------------------------------------------------
--
-- 替换视图以便查看 `SR_fullJoin`
-- (参见下面的实际视图)
--
CREATE TABLE `SR_fullJoin` (
`Tag` varchar(50)
,`cntSales` bigint
,`cntRequests` bigint
);
-- --------------------------------------------------------
--
-- 替换视图以便查看 `SR_leftJoin`
-- (参见下面的实际视图)
--
CREATE TABLE `SR_leftJoin` (
`Tag` varchar(50)
,`cntSales` bigint
,`cntRequests` bigint
);
-- --------------------------------------------------------
--
-- 替换视图以便查看 `SR_rightJoin`
-- (参见下面的实际视图)
--
CREATE TABLE `SR_rightJoin` (
`Tag` varchar(50)
,`cntSales` bigint
,`cntRequests` bigint
);
-- --------------------------------------------------------
--
-- 表的结构 `Transactions`
--
CREATE TABLE `Transactions` (
`TransactionId` int NOT NULL,
`SellerId` varchar(50) DEFAULT NULL,
`BuyerId` varchar(50) DEFAULT NULL,
`ProductName` varchar(50) DEFAULT NULL,
`Price` double DEFAULT NULL,
`Tag` varchar(50) DEFAULT NULL,
`Description` varchar(500) DEFAULT NULL,
`Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 表的结构 `Users`
--
CREATE TABLE `Users` (
`NetId` varchar(50) NOT NULL,
`Password` varchar(50) DEFAULT NULL,
`Name` varchar(50) DEFAULT NULL,
`Email` varchar(50) DEFAULT NULL,
`Campus` varchar(10) DEFAULT NULL,
`Major` varchar(10) DEFAULT NULL,
`Year` varchar(10) DEFAULT NULL,
`DateJoin` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- 转存表中的数据 `Users`
--
INSERT INTO `Users` (`NetId`, `Password`, `Name`, `Email`, `Campus`, `Major`, `Year`, `DateJoin`) VALUES
('cs411', 'cs411', 'Little Genius', '[email protected]', 'UIUC', 'CS', 'Junior', '2020-07-25 06:14:03'),
('genius', 'genius', 'Real Genius', '[email protected]', 'ZJU', 'Other', 'Graduate', '2020-07-25 07:03:09');
-- --------------------------------------------------------
--
-- 表的结构 `Visit`
--
CREATE TABLE `Visit` (
`Visit` int DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 视图结构 `SRT_leftJoin`
--
DROP TABLE IF EXISTS `SRT_leftJoin`;
CREATE ALGORITHM=UNDEFINED DEFINER=`Geniuses`@`%` SQL SECURITY DEFINER VIEW `SRT_leftJoin` AS select `SR_fullJoin`.`Tag` AS `Tag`,`SR_fullJoin`.`cntSales` AS `cntSales`,`SR_fullJoin`.`cntRequests` AS `cntRequests`,`tmp3`.`cntTrans` AS `cntTrans` from (`SR_fullJoin` left join (select `Transactions`.`Tag` AS `Tag`,count(0) AS `cntTrans` from `Transactions` group by `Transactions`.`Tag`) `tmp3` on((`SR_fullJoin`.`Tag` = `tmp3`.`Tag`))) ;
-- --------------------------------------------------------
--
-- 视图结构 `SRT_rightJoin`
--
DROP TABLE IF EXISTS `SRT_rightJoin`;
CREATE ALGORITHM=UNDEFINED DEFINER=`Geniuses`@`%` SQL SECURITY DEFINER VIEW `SRT_rightJoin` AS select `tmp3`.`Tag` AS `Tag`,`SR_fullJoin`.`cntSales` AS `cntSales`,`SR_fullJoin`.`cntRequests` AS `cntRequests`,`tmp3`.`cntTrans` AS `cntTrans` from ((select `Transactions`.`Tag` AS `Tag`,count(0) AS `cntTrans` from `Transactions` group by `Transactions`.`Tag`) `tmp3` left join `SR_fullJoin` on((`SR_fullJoin`.`Tag` = `tmp3`.`Tag`))) ;
-- --------------------------------------------------------
--
-- 视图结构 `SR_fullJoin`
--
DROP TABLE IF EXISTS `SR_fullJoin`;
CREATE ALGORITHM=UNDEFINED DEFINER=`Geniuses`@`%` SQL SECURITY DEFINER VIEW `SR_fullJoin` AS select `tmp`.`Tag` AS `Tag`,`tmp`.`cntSales` AS `cntSales`,`tmp`.`cntRequests` AS `cntRequests` from (select `SR_leftJoin`.`Tag` AS `Tag`,`SR_leftJoin`.`cntSales` AS `cntSales`,`SR_leftJoin`.`cntRequests` AS `cntRequests` from `SR_leftJoin` union select `SR_rightJoin`.`Tag` AS `Tag`,`SR_rightJoin`.`cntSales` AS `cntSales`,`SR_rightJoin`.`cntRequests` AS `cntRequests` from `SR_rightJoin`) `tmp` ;
-- --------------------------------------------------------
--
-- 视图结构 `SR_leftJoin`
--
DROP TABLE IF EXISTS `SR_leftJoin`;
CREATE ALGORITHM=UNDEFINED DEFINER=`Geniuses`@`%` SQL SECURITY DEFINER VIEW `SR_leftJoin` AS select `tmp1`.`Tag` AS `Tag`,`tmp1`.`cntSales` AS `cntSales`,`tmp2`.`cntRequests` AS `cntRequests` from ((select `Sales`.`Tag` AS `Tag`,count(0) AS `cntSales` from `Sales` group by `Sales`.`Tag`) `tmp1` left join (select `Requests`.`Tag` AS `Tag`,count(0) AS `cntRequests` from `Requests` group by `Requests`.`Tag`) `tmp2` on((`tmp1`.`Tag` = `tmp2`.`Tag`))) ;
-- --------------------------------------------------------
--
-- 视图结构 `SR_rightJoin`
--
DROP TABLE IF EXISTS `SR_rightJoin`;
CREATE ALGORITHM=UNDEFINED DEFINER=`Geniuses`@`%` SQL SECURITY DEFINER VIEW `SR_rightJoin` AS select `tmp2`.`Tag` AS `Tag`,`tmp1`.`cntSales` AS `cntSales`,`tmp2`.`cntRequests` AS `cntRequests` from ((select `Requests`.`Tag` AS `Tag`,count(0) AS `cntRequests` from `Requests` group by `Requests`.`Tag`) `tmp2` left join (select `Sales`.`Tag` AS `Tag`,count(0) AS `cntSales` from `Sales` group by `Sales`.`Tag`) `tmp1` on((`tmp1`.`Tag` = `tmp2`.`Tag`))) ;
--
-- 转储表的索引
--
--
-- 表的索引 `Requests`
--
ALTER TABLE `Requests`
ADD PRIMARY KEY (`RequestId`),
ADD KEY `Requests_ibfk_1` (`BuyerId`),
ADD KEY `Requests_ibfk_2` (`SaleId`);
--
-- 表的索引 `Sales`
--
ALTER TABLE `Sales`
ADD PRIMARY KEY (`SaleId`),
ADD KEY `Sales_ibfk_1` (`SellerId`),
ADD KEY `Sales_ibfk_2` (`IntendedBuyerId`);
--
-- 表的索引 `Transactions`
--
ALTER TABLE `Transactions`
ADD PRIMARY KEY (`TransactionId`),
ADD KEY `Transactions_ibfk_1` (`BuyerId`),
ADD KEY `Transactions_ibfk_2` (`SellerId`);
--
-- 表的索引 `Users`
--
ALTER TABLE `Users`
ADD PRIMARY KEY (`NetId`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `Requests`
--
ALTER TABLE `Requests`
MODIFY `RequestId` int NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `Sales`
--
ALTER TABLE `Sales`
MODIFY `SaleId` int NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `Transactions`
--
ALTER TABLE `Transactions`
MODIFY `TransactionId` int NOT NULL AUTO_INCREMENT;
--
-- 限制导出的表
--
--
-- 限制表 `Requests`
--
ALTER TABLE `Requests`
ADD CONSTRAINT `Requests_ibfk_1` FOREIGN KEY (`BuyerId`) REFERENCES `Users` (`NetId`) ON DELETE CASCADE ON UPDATE RESTRICT,
ADD CONSTRAINT `Requests_ibfk_2` FOREIGN KEY (`SaleId`) REFERENCES `Sales` (`SaleId`) ON DELETE CASCADE ON UPDATE RESTRICT;
--
-- 限制表 `Sales`
--
ALTER TABLE `Sales`
ADD CONSTRAINT `Sales_ibfk_1` FOREIGN KEY (`SellerId`) REFERENCES `Users` (`NetId`) ON DELETE CASCADE ON UPDATE RESTRICT,
ADD CONSTRAINT `Sales_ibfk_2` FOREIGN KEY (`IntendedBuyerId`) REFERENCES `Users` (`NetId`) ON DELETE CASCADE ON UPDATE RESTRICT;
--
-- 限制表 `Transactions`
--
ALTER TABLE `Transactions`
ADD CONSTRAINT `Transactions_ibfk_1` FOREIGN KEY (`BuyerId`) REFERENCES `Users` (`NetId`) ON DELETE CASCADE ON UPDATE RESTRICT,
ADD CONSTRAINT `Transactions_ibfk_2` FOREIGN KEY (`SellerId`) REFERENCES `Users` (`NetId`) ON DELETE CASCADE ON UPDATE RESTRICT;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;