-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookstore.sql
372 lines (312 loc) · 19.8 KB
/
bookstore.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
-- phpMyAdmin SQL Dump
-- version 4.7.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: 2017-07-09 14:28:51
-- 服务器版本: 5.6.26
-- PHP Version: 5.6.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
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 */;
--
-- Database: `bookstore`
--
CREATE DATABASE IF NOT EXISTS `bookstore` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE `bookstore`;
DELIMITER $$
--
-- 存储过程
--
CREATE DEFINER=`root`@`localhost` PROCEDURE `statAll` (IN `start_time` TIMESTAMP, IN `end_time` TIMESTAMP, OUT `stat_person` INT UNSIGNED, OUT `stat_quantity` INT UNSIGNED, OUT `stat_price` INT UNSIGNED) BEGIN
SELECT COUNT(DISTINCT user_id), SUM(quantity), SUM(quantity * price)
INTO stat_person, stat_quantity, stat_price
FROM `Order` JOIN OrderItem USING (order_id)
WHERE `Order`.is_paid = 1 AND `Order`.updated_at >= start_time AND `Order`.updated_at <= end_time;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `statBook` (IN `stat_book` INT(11) UNSIGNED, IN `start_time` TIMESTAMP, IN `end_time` TIMESTAMP, OUT `stat_person` INT UNSIGNED, OUT `stat_quantity` INT UNSIGNED, OUT `stat_price` INT UNSIGNED) BEGIN
SELECT COUNT(DISTINCT user_id), SUM(quantity), SUM(quantity * price)
INTO stat_person, stat_quantity, stat_price
FROM `Order` JOIN OrderItem USING (order_id)
WHERE `Order`.is_paid = 1 AND `Order`.updated_at >= start_time AND `Order`.updated_at <= end_time AND book_id = stat_book;
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `statCategory` (IN `stat_category` INT(11) UNSIGNED, IN `start_time` TIMESTAMP, IN `end_time` TIMESTAMP, OUT `stat_person` INT UNSIGNED, OUT `stat_quantity` INT UNSIGNED, OUT `stat_price` INT UNSIGNED) BEGIN
SELECT COUNT(DISTINCT user_id), SUM(quantity), SUM(quantity * price)
INTO stat_person, stat_quantity, stat_price
FROM `Order` JOIN OrderItem USING (order_id)
WHERE `Order`.is_paid = 1 AND `Order`.updated_at >= start_time AND `Order`.updated_at <= end_time AND book_id IN (
SELECT book_id
FROM BookCategory
WHERE category_id = stat_category
);
END$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `statUser` (IN `stat_user` VARCHAR(32), IN `start_time` TIMESTAMP, IN `end_time` TIMESTAMP, OUT `stat_orders` INT UNSIGNED, OUT `stat_items` INT UNSIGNED, OUT `stat_quantity` INT UNSIGNED, OUT `stat_price` INT UNSIGNED) BEGIN
SELECT COUNT(DISTINCT order_id), COUNT(item_id), SUM(quantity), SUM(quantity * price)
INTO stat_orders, stat_items, stat_quantity, stat_price
FROM `Order` JOIN OrderItem USING (order_id)
WHERE `Order`.is_paid = 1 AND `Order`.updated_at >= start_time AND `Order`.updated_at <= end_time AND user_id = (
SELECT user_id
FROM User
WHERE username = stat_user
);
END$$
DELIMITER ;
-- --------------------------------------------------------
--
-- 表的结构 `Book`
--
CREATE TABLE `Book` (
`book_id` int(11) UNSIGNED NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`image` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`author` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`press` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`price` int(11) UNSIGNED NOT NULL COMMENT '单位:分',
`stock` int(11) UNSIGNED NOT NULL,
`description` text COLLATE utf8_unicode_ci,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `Book`
--
INSERT INTO `Book` (`book_id`, `name`, `image`, `author`, `press`, `price`, `stock`, `description`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, 'MySQL:从删库到跑路', '127aa37c079312a930e820cbe2e2794be70e9d16_1496288119675_904.jpg', '', '', 6530, 5, '听说最近数据库界忽然流传起来一本书,叫《MySQL:从删库到跑路》。\n我看了前几章节,大概介绍的暗黑界的程序员怎么写坑,怎么悄无声息甩锅给老实忠厚的程序员,还有最后怎么删除数据库之后遁入尘世不见踪影,手法之巧妙,策略之精巧,简直就是删库于无形之中。\n记得第一章有段序是这样写的“来呀 快活呀 反正有大把bug”,我看后吓出一身冷汗。', '2017-05-02 08:28:00', '2017-07-09 11:16:38', NULL),
(2, '黑客攻防:从入门到入狱', '7e10feca133ddc0376a576fc71e3ece163abbec2_1496288132553_961.jpg', '', '', 8860, 2, '', '2017-05-02 08:30:22', '2017-06-01 11:55:11', NULL),
(3, 'PHP:世界上最好的语言', '', '', '', 2880, 20, '某女:你能让这个论坛的人都吵起来,我今晚就跟你走。 \n某软件工程师:PHP是最好的语言! \n某论坛炸锅了,各种吵架... \n某女:服了你了,我们走吧,你想干啥都行。\n某软件工程师:今天不行,我一定要说服他们,PHP必须是最好的语言 。\n某女:.......', '2017-05-02 08:34:11', '2017-05-02 08:34:11', '2017-05-02 08:46:11'),
(4, 'Java编程思想', '07cafe83ce4581ed1a270079fbfd04a16c6093f6_1496288143105_623.jpg', 'Bruce Eckel 著 陈昊鹏 译', '机械工业出版社', 8640, 97, '本书赢得了全球程序员的广泛赞誉,即使是最晦涩的概念,在Bruce Eckel的文字亲和力和小而直接的编程示例面前也会化解于无形。从Java的基础语法到最高级特性(深入的面向对象概念、多线程、自动项目构建、单元测试和调试等),本书都能逐步指导你轻松掌握。\n从本书获得的各项大奖以及来自世界各地的读者评论中,不难看出这是一本经典之作。本书的作者拥有多年教学经验,对C、C++以及Java语言都有独到、深入的见解,以通俗易懂及小而直接的示例解释了一个个晦涩抽象的概念。本书共22章,包括操作符、控制执行流程、访问权限控制、复用类、多态、接口、通过异常处理错误、字符串、泛型、数组、容器深入研究、JavaI/O系统、枚举类型、并发以及图形化用户界面等内容。这些丰富的内容,包含了Java语言基础语法以及高级特性,适合各个层次的Java程序员阅读,同时也是高等院校讲授面向对象程序设计语言以及Java语言的绝佳教材和参考书。', '2017-05-02 08:37:57', '2017-06-01 03:35:44', NULL),
(5, '深入理解计算机系统(原书第3版)', '49a5678220e26a62c8819d3a355c1e09de266462_1496288152474_638.jpg', '(美) Randal E.Bryant', '机械工业出版社', 11120, 199, '本书主要介绍了计算机系统的基本概念,包括最底层的内存中的数据表示、流水线指令的构成、虚拟存储器、编译系统、动态加载库,以及用户应用等。书中提供了大量实际操作,可以帮助读者更好地理解程序执行的方式,改进程序的执行效率。此书以程序员的视角全面讲解了计算机系统,深入浅出地介绍了处理器、编译器、操作系统和网络环境,是这一领域的权威之作。\n本书适合作为计算机及相关专业的本科生教材,同时也适用于编程人员参考阅读。', '2017-05-02 08:41:20', '2017-07-09 08:46:02', NULL),
(6, '活着', '3c04096a078abc67f6690ca1c9c5db7f1af701ff_1496288162718_338.jpg', '余华', '作家出版社', 1000, 25, '《活着》是一部充满血泪的小说。余华通过一位中国农民的苦难生活讲述了人如何去承受巨大的苦难;讲述了眼泪的丰富和宽广;讲述了绝望的不存在:讲述了人是为了活着本身而活着…… \n《活着》这部小说荣获意大利格林扎纳·卡佛文学奖*奖项(1998年 ),台湾《中国时报》10本好书奖(1994年),香港“博益”15本好书奖 (1990年);并入选香港《亚洲周刊》评选的“20世纪中文小说百年百强” ;入选中国百位批评家和文学编辑评选的“九十年代*有影响的10部作品 ”。', '2017-05-02 08:43:29', '2017-06-01 03:36:04', NULL),
(7, '津巴多普通心理学(原书第7版)', 'ddec559241cd6fc3ac6100730566f9016aaa326c_1496288172253_523.jpg', '(美) 菲利普·津巴多、 (美) 罗伯特·约翰逊、(美) 薇薇安·麦卡恩', '中国人民大学出版社', 8930, 145, '享誉全球的心理学大师、“当代心理学的形象与声音”菲利普·津巴多主笔,凝聚作者50多年第一手教育经验。\n北京师范大学、清华大学、浙江大学、西南大学、南京大学、东北师范大学心理学名师联袂推荐。清华大学普通心理学主讲钱静倾情翻译。\n自从2008 年前一版《津巴多普通心理学》中文版出版以来,心理学经历了巨大的改变。从前一版教材到现在的第7版,津巴多教授历时8年做出了近60%的更新,加入了大量新的研究发展以及全新的案例。\n以问题串联概念,构建系统的知识网络,让学习更符合认知规律,帮助不爱学习的学生也能爱上心理学。\n强调批判性思维。总结6大批判性思维技能,引领读者深入思考14个富有争议性的心理学问题,不仅介绍心理学知识,更注重培养心理学的思维方式。\n参与性强。设有“亲自实践”“生活中的心理学”等富有参与性的专栏,鼓励学生学以致用,在生活实践中加深对心理学的理解。\n语言幽默,形式多样。来自生活方方面面的案例让心理学变得好用又有趣;每章末尾还附有津巴多教授主持的26集科教片《探索心理学》的节目链接及观看指南。读者评价这是比小说还好看的教材。', '2017-05-02 08:46:03', '2017-06-01 03:36:14', NULL),
(8, '<script>alert(\'xss!\')</script>', 'f7a7dcbd8d7db9c5b34f21ee44e5c44b6d606bf2_1496288184336_331.png', '<script>alert(\'xss!\')</script>', '<script>alert(\'xss!\')</script>', 10, 0, '<script>alert(\'xss!\')</script>', '2017-05-02 08:47:36', '2017-07-09 08:59:51', NULL),
(9, '\'; drop database bookstore --', '6b2d096f02e4f303bb5023f909a492ae2e499aaf_1496288195805_589.jpg', '\'; drop database bookstore --', '\'; drop database bookstore --', 20, 0, '\'; drop database bookstore --', '2017-05-02 08:48:14', '2017-07-09 08:59:51', NULL),
(28, '一本书', '', '没有作者', '没有出版社', 0, 0, '没有介绍\n就是没有介绍', '2017-06-01 03:04:09', '2017-06-01 03:04:09', '2017-06-01 03:04:20'),
(29, '_\\', '', '', '', 0, 0, '', '2017-06-24 09:28:52', '2017-06-24 09:28:52', NULL),
(30, '`%1', '', '', '', 0, 0, '', '2017-06-24 09:29:00', '2017-06-24 13:30:02', NULL);
-- --------------------------------------------------------
--
-- 表的结构 `BookCategory`
--
CREATE TABLE `BookCategory` (
`bc_id` int(11) UNSIGNED NOT NULL,
`category_id` int(11) UNSIGNED NOT NULL,
`book_id` int(11) UNSIGNED NOT NULL,
`created_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `BookCategory`
--
INSERT INTO `BookCategory` (`bc_id`, `category_id`, `book_id`, `created_at`) VALUES
(1, 1, 1, '2017-05-27 16:00:00'),
(2, 2, 1, '2017-05-27 16:00:00'),
(3, 1, 2, '2017-06-09 11:48:51'),
(6, 4, 1, '2017-06-09 13:29:53'),
(7, 6, 2, '2017-06-09 13:30:05'),
(8, 1, 4, '2017-06-09 13:30:11'),
(9, 1, 5, '2017-06-09 13:30:18'),
(10, 5, 6, '2017-06-09 13:30:23'),
(11, 6, 30, '2017-06-24 14:20:46');
-- --------------------------------------------------------
--
-- 表的结构 `Category`
--
CREATE TABLE `Category` (
`category_id` int(11) UNSIGNED NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `Category`
--
INSERT INTO `Category` (`category_id`, `name`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, '计算机', '2017-05-27 16:00:00', '2017-06-04 13:23:10', NULL),
(2, '搞笑', '2017-05-27 16:00:00', '2017-06-04 13:23:12', NULL),
(4, '数据库', '2017-06-04 12:48:10', '2017-06-04 13:20:27', NULL),
(5, '文学', '2017-06-04 12:48:27', '2017-06-04 13:17:54', NULL),
(6, '<script>alert(\'xss\');</script>', '2017-06-04 13:27:56', '2017-06-04 13:30:05', NULL),
(7, 'hahaha', '2017-06-04 13:28:04', '2017-06-04 13:28:04', '2017-06-04 13:28:31');
-- --------------------------------------------------------
--
-- 表的结构 `Order`
--
CREATE TABLE `Order` (
`order_id` int(11) UNSIGNED NOT NULL,
`user_id` int(11) UNSIGNED NOT NULL,
`is_paid` tinyint(1) UNSIGNED NOT NULL,
`total_price` int(11) UNSIGNED DEFAULT NULL COMMENT '单位:分',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `Order`
--
INSERT INTO `Order` (`order_id`, `user_id`, `is_paid`, `total_price`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, 1, 1, 77100, '2017-05-02 10:00:00', '2017-05-28 15:34:53', NULL),
(2, 2, 1, 33110, '2017-05-02 10:00:00', '2017-06-01 11:55:11', NULL),
(3, 1, 1, 6530, '2017-05-28 15:34:53', '2017-05-31 14:24:24', '2017-05-31 14:27:24'),
(4, 1, 1, 11120, '2017-05-31 14:24:24', '2017-05-31 15:12:08', '2017-05-31 15:45:45'),
(5, 1, 1, 50, '2017-05-31 15:12:08', '2017-07-09 08:59:51', NULL),
(6, 12, 0, NULL, '2017-05-31 15:13:19', '2017-05-31 15:13:19', NULL),
(7, 13, 0, NULL, '2017-06-01 03:00:27', '2017-06-01 03:00:27', NULL),
(8, 14, 0, NULL, '2017-06-01 03:00:58', '2017-06-01 03:00:58', NULL),
(10, 2, 0, NULL, '2017-06-01 11:55:11', '2017-06-01 11:55:11', NULL),
(11, 1, 0, NULL, '2017-07-09 08:59:51', '2017-07-09 08:59:51', NULL),
(12, 15, 0, NULL, '2017-07-09 09:29:32', '2017-07-09 09:29:32', NULL);
-- --------------------------------------------------------
--
-- 表的结构 `OrderItem`
--
CREATE TABLE `OrderItem` (
`item_id` int(11) UNSIGNED NOT NULL,
`order_id` int(11) UNSIGNED NOT NULL,
`book_id` int(11) UNSIGNED NOT NULL,
`price` int(11) UNSIGNED DEFAULT NULL COMMENT '单位:分',
`quantity` int(11) UNSIGNED NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `OrderItem`
--
INSERT INTO `OrderItem` (`item_id`, `order_id`, `book_id`, `price`, `quantity`, `created_at`, `updated_at`) VALUES
(1, 1, 4, 8640, 3, '2017-05-02 10:00:00', '2017-05-28 15:34:53'),
(2, 1, 1, 6530, 1, '2017-05-02 10:00:00', '2017-05-28 15:34:53'),
(3, 1, 7, 8930, 5, '2017-05-02 10:00:00', '2017-05-28 15:34:53'),
(7, 2, 1, 6530, 1, '2017-05-28 13:43:02', '2017-06-01 11:55:11'),
(13, 3, 1, 6530, 1, '2017-05-31 14:24:20', '2017-05-31 14:24:24'),
(15, 4, 5, 11120, 1, '2017-05-31 15:07:59', '2017-05-31 15:12:08'),
(16, 2, 2, 8860, 3, '2017-06-01 11:54:48', '2017-06-01 11:55:11'),
(17, 5, 9, 20, 2, '2017-06-03 04:24:33', '2017-07-09 08:59:51'),
(19, 5, 8, 10, 1, '2017-06-09 13:35:25', '2017-07-09 08:59:51'),
(20, 10, 5, NULL, 1, '2017-07-08 13:42:01', '2017-07-08 13:42:01');
-- --------------------------------------------------------
--
-- 表的结构 `User`
--
CREATE TABLE `User` (
`user_id` int(11) UNSIGNED NOT NULL,
`username` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
`nickname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`avatar` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`balance` int(11) UNSIGNED NOT NULL COMMENT '单位:分',
`role` tinyint(1) UNSIGNED NOT NULL COMMENT '0为普通用户,1为管理员',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- 转存表中的数据 `User`
--
INSERT INTO `User` (`user_id`, `username`, `password`, `nickname`, `avatar`, `balance`, `role`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, 'admin', 'bcb15f821479b4d5772bd0ca866c00ad5f926e3580720659cc80d39c9d09802a', '系统管理员', '787fac4d19cdbae82a3edcf33499f274511d67cd_1499587390815_133.jpg', 9052000, 1, '2017-05-02 08:53:21', '2017-07-09 08:59:51', NULL),
(2, 'testuser', 'bcb15f821479b4d5772bd0ca866c00ad5f926e3580720659cc80d39c9d09802a', '测试用户', '61fd4edca58a0fa8376e50a1edebd35c2bcde346_1496288216285_386.png', 66890, 0, '2017-05-02 08:58:07', '2017-07-09 08:02:53', NULL),
(12, 'newuser', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92', '小王', '', 66600, 0, '2017-05-31 15:13:19', '2017-07-09 11:30:40', NULL),
(13, 'hacker1', 'e7d3685715939842749cc27b38d0ccb9706d4d14a5304ef9eee093780eab5df9', '<script>alert(\'xss\');</script>', 'f7a7dcbd8d7db9c5b34f21ee44e5c44b6d606bf2_1496288230350_460.png', 0, 0, '2017-06-01 03:00:26', '2017-06-01 03:37:12', NULL),
(14, 'hacker2', 'e7d3685715939842749cc27b38d0ccb9706d4d14a5304ef9eee093780eab5df9', '\' or 1=1 --', '6b2d096f02e4f303bb5023f909a492ae2e499aaf_1496288239650_173.jpg', 0, 0, '2017-06-01 03:00:58', '2017-06-01 03:37:21', NULL),
(15, 'ahaaha', '3ea87a56da3844b420ec2925ae922bc731ec16a4fc44dcbeafdad49b0e61d39c', '啊哈啊哈', '', 0, 0, '2017-07-09 09:29:32', '2017-07-09 09:31:33', NULL);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `Book`
--
ALTER TABLE `Book`
ADD PRIMARY KEY (`book_id`);
--
-- Indexes for table `BookCategory`
--
ALTER TABLE `BookCategory`
ADD PRIMARY KEY (`bc_id`),
ADD KEY `FK_Reference_4` (`book_id`),
ADD KEY `FK_Reference_5` (`category_id`);
--
-- Indexes for table `Category`
--
ALTER TABLE `Category`
ADD PRIMARY KEY (`category_id`);
--
-- Indexes for table `Order`
--
ALTER TABLE `Order`
ADD PRIMARY KEY (`order_id`),
ADD KEY `FK_Reference_1` (`user_id`);
--
-- Indexes for table `OrderItem`
--
ALTER TABLE `OrderItem`
ADD PRIMARY KEY (`item_id`),
ADD KEY `FK_Reference_2` (`order_id`),
ADD KEY `FK_Reference_3` (`book_id`);
--
-- Indexes for table `User`
--
ALTER TABLE `User`
ADD PRIMARY KEY (`user_id`),
ADD UNIQUE KEY `username` (`username`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `Book`
--
ALTER TABLE `Book`
MODIFY `book_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
--
-- 使用表AUTO_INCREMENT `BookCategory`
--
ALTER TABLE `BookCategory`
MODIFY `bc_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
--
-- 使用表AUTO_INCREMENT `Category`
--
ALTER TABLE `Category`
MODIFY `category_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
--
-- 使用表AUTO_INCREMENT `Order`
--
ALTER TABLE `Order`
MODIFY `order_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- 使用表AUTO_INCREMENT `OrderItem`
--
ALTER TABLE `OrderItem`
MODIFY `item_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;
--
-- 使用表AUTO_INCREMENT `User`
--
ALTER TABLE `User`
MODIFY `user_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
--
-- 限制导出的表
--
--
-- 限制表 `BookCategory`
--
ALTER TABLE `BookCategory`
ADD CONSTRAINT `FK_Reference_4` FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`),
ADD CONSTRAINT `FK_Reference_5` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`);
--
-- 限制表 `Order`
--
ALTER TABLE `Order`
ADD CONSTRAINT `FK_Reference_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`);
--
-- 限制表 `OrderItem`
--
ALTER TABLE `OrderItem`
ADD CONSTRAINT `FK_Reference_2` FOREIGN KEY (`order_id`) REFERENCES `order` (`order_id`),
ADD CONSTRAINT `FK_Reference_3` FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`);
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 */;