-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate.sql
More file actions
302 lines (136 loc) · 5.26 KB
/
create.sql
File metadata and controls
302 lines (136 loc) · 5.26 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
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
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40103 SET SQL_NOTES='ON' */;
DROP DATABASE
IF EXISTS `second_hand`;
CREATE DATABASE `second_hand` DEFAULT
CHARSET utf8;
USE second_hand;
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(32) DEFAULT NULL,
`level` tinyint DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_admin_username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for cart
-- ----------------------------
DROP TABLE IF EXISTS `cart`;
CREATE TABLE `cart` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uId` int(11) NOT NULL,
`pId` int(11) NOT NULL,
`count` int(11) DEFAULT NULL,
`isBuy` enum('是','否') NOT NULL DEFAULT '否',
`totalPrice` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_user_id` (`uId`),
KEY `fk_product_id` (`pId`),
CONSTRAINT `fk_cart_user_id` FOREIGN KEY (`uId`) REFERENCES `user` (`id`),
CONSTRAINT `fk_cart_product_id` FOREIGN KEY (`pId`) REFERENCES `product` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for hot
-- ----------------------------
DROP TABLE IF EXISTS `hot`;
CREATE TABLE `hot` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pId` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_product_id` (`pId`),
CONSTRAINT `fk_hot_product_id` FOREIGN KEY (`pId`) REFERENCES `product` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for kind
-- ----------------------------
DROP TABLE IF EXISTS `kind`;
CREATE TABLE `kind` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`kName` varchar(16) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_kind_kname` (`kName`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for product
-- ----------------------------
DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uId` int(11) NOT NULL,
`kId` int(11) NOT NULL,
`pName` varchar(64) DEFAULT NULL,
`pDesc` text,
`pNum` int(11) DEFAULT NULL,
`pImage` varchar(255) DEFAULT NULL,
`realPrice` int(11) DEFAULT '0',
`originPrice` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_product` (`uId`,`pName`),
KEY `fk_kid` (`kId`),
KEY `fk_uid` (`uId`),
CONSTRAINT `fk_product_kind_id` FOREIGN KEY (`kId`) REFERENCES `kind` (`id`),
CONSTRAINT `fk_product_user_id` FOREIGN KEY (`uId`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=100032 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for product_image
-- ----------------------------
DROP TABLE IF EXISTS `product_image`;
CREATE TABLE `product_image` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pId` int(11) NOT NULL,
`imageType` varchar(32) DEFAULT NULL,
`imageName` varchar(64) DEFAULT NULL,
`imageSrc` text,
PRIMARY KEY (`id`),
UNIQUE KEY `unque_image_name` (`imageName`),
KEY `fk_product_id` (`pId`),
CONSTRAINT `fk_product_image_product_id` FOREIGN KEY (`pId`) REFERENCES `product` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=100032 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for sales
-- ----------------------------
DROP TABLE IF EXISTS `sales`;
CREATE TABLE `sales` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uId` int(11) NOT NULL,
`pId` int(11) NOT NULL,
`count` int(11) DEFAULT NULL,
`totalPrice` int(11) DEFAULT '0',
`orderDate` datetime DEFAULT NULL,
`invoiceNo` char(15) DEFAULT NULL,
`orderStatus` varchar(10) DEFAULT NULL,
`delivDate` datetime DEFAULT NULL,
`contactMan` varchar(10) DEFAULT NULL,
`contactTel` varchar(11) DEFAULT NULL,
`contactAddr` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_user_id` (`uId`),
KEY `fk_product_id` (`pId`),
CONSTRAINT `fk_sales_user_id` FOREIGN KEY (`uId`) REFERENCES `user` (`id`),
CONSTRAINT `fk_sales_product_id` FOREIGN KEY (`pId`) REFERENCES `product` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(64) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(32) DEFAULT NULL,
`tel` varchar(20) DEFAULT NULL,
`sex` varchar(20) DEFAULT '保密',
`level` tinyint DEFAULT '1',
`score` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_user_username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;