-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathdb.sql
More file actions
100 lines (89 loc) · 2.8 KB
/
db.sql
File metadata and controls
100 lines (89 loc) · 2.8 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
-- Create Database
CREATE DATABASE trainbookingDB;
-- Use the database
USE trainbookingDB;
-- Table for storing schedule details
CREATE TABLE schedule (
id INT PRIMARY KEY,
name VARCHAR(100)
);
-- Table for storing train journey details
CREATE TABLE train_journey (
id INT PRIMARY KEY,
schedule_id INT NOT NULL,
name VARCHAR(100) NOT NULL,
FOREIGN KEY (schedule_id) REFERENCES schedule(id)
);
-- Table for storing train station details
CREATE TABLE train_station (
id INT PRIMARY KEY,
station_name VARCHAR(200)
);
-- Table to store the relationship between journeys and stations
CREATE TABLE journey_station (
journey_id INT NOT NULL,
station_id INT NOT NULL,
stop_order INT NOT NULL,
departure_time TIMESTAMP NOT NULL,
PRIMARY KEY (journey_id, station_id),
FOREIGN KEY (journey_id) REFERENCES train_journey(id),
FOREIGN KEY (station_id) REFERENCES train_station(id)
);
-- Table for different carriage classes
CREATE TABLE carriage_class (
id INT PRIMARY KEY AUTO_INCREMENT,
class_name VARCHAR(100) NOT NULL,
seating_capacity INT NOT NULL
);
-- Table to store pricing information for each schedule and carriage class
CREATE TABLE carriage_price (
schedule_id INT,
carriage_class_id INT,
price DECIMAL(10,2),
FOREIGN KEY (schedule_id) REFERENCES schedule(id),
FOREIGN KEY (carriage_class_id) REFERENCES carriage_class(id)
);
-- Table to store the relationship between journeys and carriages
CREATE TABLE journey_carriage (
journey_id INT NOT NULL,
carriage_class_id INT NOT NULL,
position INT NOT NULL,
PRIMARY KEY (journey_id, carriage_class_id),
FOREIGN KEY (journey_id) REFERENCES train_journey(id),
FOREIGN KEY (carriage_class_id) REFERENCES carriage_class(id)
);
-- Table for storing booking statuses
CREATE TABLE booking_status (
id INT PRIMARY KEY,
name VARCHAR(100)
);
-- Table for storing passenger details
CREATE TABLE passenger (
id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email_address VARCHAR(100),
password VARCHAR(100)
);
-- Table for storing booking details
CREATE TABLE booking (
id INT PRIMARY KEY,
carriage_class_id INT,
passenger_id INT,
position INT,
status_id INT,
booking_date TIMESTAMP,
starting_station_id INT,
ending_station_id INT,
train_journey_id INT,
ticket_class_id INT,
amount_paid INT,
ticket_no INT,
seat_no INT,
FOREIGN KEY (passenger_id) REFERENCES passenger(id),
FOREIGN KEY (status_id) REFERENCES booking_status(id),
FOREIGN KEY (starting_station_id) REFERENCES train_station(id),
FOREIGN KEY (ending_station_id) REFERENCES train_station(id),
FOREIGN KEY (train_journey_id) REFERENCES train_journey(id),
FOREIGN KEY (ticket_class_id) REFERENCES carriage_class(id)
);