-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_system.sql
152 lines (138 loc) · 7.52 KB
/
train_system.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
/*
Navicat Premium Data Transfer
Source Server : sa
Source Server Type : MySQL
Source Server Version : 80100
Source Host : localhost:3306
Source Schema : train_system
Target Server Type : MySQL
Target Server Version : 80100
File Encoding : 65001
Date: 18/12/2023 16:51:12
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for administrator
-- ----------------------------
DROP TABLE IF EXISTS `administrator`;
CREATE TABLE `administrator` (
`account` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`username` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`name` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`password` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`phone` char(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
PRIMARY KEY (`account`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for arrival_time
-- ----------------------------
DROP TABLE IF EXISTS `arrival_time`;
CREATE TABLE `arrival_time` (
`train_number` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`station_name` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`arrival_time` time(0) NOT NULL,
`stop_order` smallint(0) NOT NULL,
PRIMARY KEY (`train_number`, `station_name`, `stop_order`) USING BTREE,
INDEX `arrival_time_ibfk_2`(`station_name`) USING BTREE,
CONSTRAINT `arrival_time_ibfk_1` FOREIGN KEY (`train_number`) REFERENCES `train` (`train_number`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for order
-- ----------------------------
DROP TABLE IF EXISTS `order`;
CREATE TABLE `order` (
`order_number` char(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`purchase_time` datetime(0) NOT NULL,
`payment_amount` smallint(0) NOT NULL,
`payment_method` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`status` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`user_account` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
PRIMARY KEY (`order_number`) USING BTREE,
INDEX `user_account`(`user_account`) USING BTREE,
CONSTRAINT `order_ibfk_1` FOREIGN KEY (`user_account`) REFERENCES `user` (`account`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for passenger
-- ----------------------------
DROP TABLE IF EXISTS `passenger`;
CREATE TABLE `passenger` (
`name` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`id_number` char(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`phone` char(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`identity` tinyint(1) NULL DEFAULT 0,
PRIMARY KEY (`id_number`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for person_info
-- ----------------------------
DROP TABLE IF EXISTS `person_info`;
CREATE TABLE `person_info` (
`account` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`id_number` char(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
PRIMARY KEY (`account`, `id_number`) USING BTREE,
INDEX `id_number`(`id_number`) USING BTREE,
INDEX `index_account`(`account`) USING BTREE,
CONSTRAINT `person_info_ibfk_1` FOREIGN KEY (`account`) REFERENCES `user` (`account`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `person_info_ibfk_2` FOREIGN KEY (`id_number`) REFERENCES `passenger` (`id_number`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for seats
-- ----------------------------
DROP TABLE IF EXISTS `seats`;
CREATE TABLE `seats` (
`train_number` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`date` date NOT NULL,
`remaining_seats` smallint(0) NOT NULL,
PRIMARY KEY (`train_number`, `date`) USING BTREE,
CONSTRAINT `seats_ibfk_1` FOREIGN KEY (`train_number`) REFERENCES `train` (`train_number`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for ticket
-- ----------------------------
DROP TABLE IF EXISTS `ticket`;
CREATE TABLE `ticket` (
`ticket_number` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`train_number` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`departure_station` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`destination_station` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`fare` smallint(0) NOT NULL,
`date` date NOT NULL,
`id_number` char(18) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`order_number` char(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`departure_time` time(0) NOT NULL,
`arrival_time` time(0) NOT NULL,
PRIMARY KEY (`ticket_number`) USING BTREE,
INDEX `train_number`(`train_number`) USING BTREE,
INDEX `id_number`(`id_number`) USING BTREE,
INDEX `order_number`(`order_number`) USING BTREE,
INDEX `departure_station`(`departure_station`) USING BTREE,
INDEX `destination_station`(`destination_station`) USING BTREE,
CONSTRAINT `ticket_ibfk_1` FOREIGN KEY (`train_number`) REFERENCES `train` (`train_number`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `ticket_ibfk_2` FOREIGN KEY (`id_number`) REFERENCES `passenger` (`id_number`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `ticket_ibfk_3` FOREIGN KEY (`order_number`) REFERENCES `order` (`order_number`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for train
-- ----------------------------
DROP TABLE IF EXISTS `train`;
CREATE TABLE `train` (
`train_number` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`seats_num` smallint(0) NOT NULL,
`train_type` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`mileage` smallint(0) NOT NULL,
PRIMARY KEY (`train_number`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`account` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`username` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`password` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
`noOfOrder` smallint(0) NULL DEFAULT 30,
PRIMARY KEY (`account`) USING BTREE,
INDEX `index_account`(`account`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;