-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDatabase.txt
282 lines (251 loc) · 10 KB
/
Database.txt
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
-- Create the database
CREATE DATABASE IF NOT EXISTS ticket_booking_db;
-- Use the database
USE ticket_booking_db;
-- Create the Bus table
CREATE TABLE IF NOT EXISTS Bus (
BusID INT PRIMARY KEY AUTO_INCREMENT,
NumberPlate VARCHAR(15) UNIQUE,
NumberOfSeats INT
);
-- Create the Route table
CREATE TABLE IF NOT EXISTS Route (
RouteID INT PRIMARY KEY AUTO_INCREMENT,
StartLocation VARCHAR(50),
EndLocation VARCHAR(50)
);
-- Create the Trip table
CREATE TABLE IF NOT EXISTS Trip (
TripID INT PRIMARY KEY AUTO_INCREMENT,
BusID INT,
RouteID INT,
StartTime TIMESTAMP,
EndTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Price DECIMAL(10, 2),
FOREIGN KEY (BusID) REFERENCES Bus(BusID),
FOREIGN KEY (RouteID) REFERENCES Route(RouteID)
);
-- Create the DiscountPass table
CREATE TABLE IF NOT EXISTS DiscountPass (
DiscountPassID INT PRIMARY KEY AUTO_INCREMENT,
PassName VARCHAR(30) UNIQUE,
DiscountPercentage FLOAT
);
-- Create the Customer table
CREATE TABLE IF NOT EXISTS Customer (
CustomerID INT PRIMARY KEY AUTO_INCREMENT,
CustomerName VARCHAR(30),
CustomerNumber CHAR(10) UNIQUE,
CustomerEmail VARCHAR(20) UNIQUE,
CustomerDOB DATE,
Password VARCHAR(15),
DiscountPassID INT,
FOREIGN KEY (DiscountPassID) REFERENCES DiscountPass(DiscountPassID)
);
-- Create the Passenger table
CREATE TABLE IF NOT EXISTS Passenger (
PassengerID INT PRIMARY KEY AUTO_INCREMENT,
PassengerName VARCHAR(30),
PassengerNumber CHAR(10) UNIQUE,
PassengerEmail VARCHAR(20) UNIQUE,
PassengerDOB DATE,
DiscountPassID INT,
AssociatedWith INT,
FOREIGN KEY (DiscountPassID) REFERENCES DiscountPass(DiscountPassID),
FOREIGN KEY (AssociatedWith) REFERENCES Customer(CustomerID)
);
-- Create the Ticket table
CREATE TABLE IF NOT EXISTS Ticket (
TicketID INT PRIMARY KEY AUTO_INCREMENT,
TripID INT,
BookedBy INT,
BookedFor INT,
BookTime TIMESTAMP,
FOREIGN KEY (TripID) REFERENCES Trip(TripID),
FOREIGN KEY (BookedBy) REFERENCES Customer(CustomerID),
FOREIGN KEY (BookedFor) REFERENCES Passenger(PassengerID)
);
-- Create table Admin
CREATE TABLE IF NOT EXISTS Admin (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(50) NOT NULL
);
-- Insert base user root
INSERT INTO Admin (username, password) VALUES ('root', '(7f*H7jTek6f7($Z');
-- Views
-- View to get all BusID
CREATE VIEW AllBusIDs AS
SELECT BusID FROM Bus;
-- View to get all RouteID
CREATE VIEW AllRouteIDs AS
SELECT RouteID FROM Route;
-- View to get all DiscountPassID
CREATE VIEW AllDiscountPassIDs AS
SELECT DiscountPassID FROM DiscountPass;
-- Trigger
DELIMITER $$
CREATE TRIGGER after_customer_insert
AFTER INSERT ON Customer
FOR EACH ROW
BEGIN
INSERT INTO Passenger (PassengerName, PassengerNumber, PassengerEmail, PassengerDOB, DiscountPassID, AssociatedWith)
VALUES (NEW.CustomerName, NEW.CustomerNumber, NEW.CustomerEmail, NEW.CustomerDOB, NEW.DiscountPassID, NEW.CustomerID);
END$$
DELIMITER ;
-- As all customers are passengers
-- View to get all Bus
CREATE VIEW AllBus AS
SELECT * FROM Bus;
-- View to get all Route
CREATE VIEW AllRoute AS
SELECT * FROM Route;
-- View to get all DiscountPass
CREATE VIEW AllDiscountPass AS
SELECT * FROM DiscountPass;
-- Values to Insert
INSERT INTO DiscountPass (PassName, DiscountPercentage)
VALUES
('No Pass', 0.0),
('Womens Pass', 10.0),
('Veteran Pass', 20.0),
('Army Pass', 15.0),
('Disabled Pass', 30.0),
('Senior Citizen Pass', 15.0),
('Student Pass', 25.0),
('Family Pass', 12.0),
('Group Pass', 8.0),
('Loyalty Pass', 5.0),
('Employee Pass', 30.0),
('Referral Pass', 10.0),
('Birthday Pass', 20.0),
('Anniversary Pass', 15.0),
('Weekend Pass', 8.0),
('Weekday Pass', 5.0),
('Early Bird Pass', 10.0),
('Night Owl Pass', 15.0),
('Seasonal Pass', 20.0),
('Holiday Pass', 25.0),
('Special Occasion Pass', 12.0),
('Student Family Pass', 18.0),
('Senior Couple Pass', 22.0),
('Military Family Pass', 25.0),
('Disabled Companion Pass', 35.0),
('Frequent Traveler Pass', 10.0);
INSERT INTO Bus (NumberPlate, NumberOfSeats)
VALUES
('MH01XY1234', 50),
('GJ02AB4567', 45),
('DL03CD7890', 60),
('UP04EF1234', 55),
('RJ05GH5678', 40),
('MP06IJ7890', 50),
('WB07KL1234', 45),
('TN08MN4567', 60),
('AP09OP7890', 55),
('KA10QR1234', 40),
('KL11ST5678', 50),
('TS12UV7890', 45),
('CG13WX1234', 60),
('OR14YZ4567', 55),
('JH15AB7890', 40),
('JK16CD1234', 50),
('HP17EF4567', 45),
('PB18GH7890', 60),
('CH19IJ1234', 55),
('AR20KL4567', 40),
('MH22YZ5678', 48),
('GJ23AB1234', 52),
('DL24CD4567', 45),
('UP25EF7890', 50),
('RJ26GH1234', 42);
INSERT INTO Route (StartLocation, EndLocation)
VALUES
('Mumbai', 'Delhi'),
('Bangalore', 'Chennai'),
('Kolkata', 'Hyderabad'),
('Pune', 'Goa'),
('Jaipur', 'Agra'),
('Ahmedabad', 'Surat'),
('Lucknow', 'Kanpur'),
('Bhopal', 'Indore'),
('Nagpur', 'Raipur'),
('Patna', 'Ranchi'),
('Chandigarh', 'Shimla'),
('Guwahati', 'Shillong'),
('Kochi', 'Thiruvananthapuram'),
('Bhubaneswar', 'Puri'),
('Srinagar', 'Leh'),
('Darjeeling', 'Gangtok'),
('Udaipur', 'Jodhpur'),
('Varanasi', 'Allahabad'),
('Mysore', 'Bangalore'),
('Amritsar', 'Chandigarh'),
('Mumbai', 'Pune'),
('Bangalore', 'Hyderabad'),
('Kolkata', 'Chennai'),
('Delhi', 'Jaipur'),
('Ahmedabad', 'Indore');
INSERT INTO Customer (CustomerName, CustomerNumber, CustomerEmail, CustomerDOB, Password, DiscountPassID)
VALUES
('Olivia Martinez', '9876543211', '[email protected]', '1995-11-23', 'password123', 5),
('Ethan Brown', '1234567891', '[email protected]', '1988-04-15', 'password456', 2),
('Sophia Lee', '7894561231', '[email protected]', '1992-07-08', 'password789', 1),
('Noah Davis', '3456789013', '[email protected]', '1991-02-21', 'password101', 10),
('Ava Miller', '5678901235', '[email protected]', '1993-09-12', 'password111', 15),
('William Johnson', '9012345679', '[email protected]', '1987-03-25', 'password122', 8),
('Mia Carter', '2345678902', '[email protected]', '1994-06-18', 'password133', 3),
('James Smith', '6789012346', '[email protected]', '1989-11-11', 'password144', 12),
('Evelyn Anderson', '8901234568', '[email protected]', '1990-05-04', 'password155', 18),
('Benjamin Wilson', '1234567892', '[email protected]', '1992-08-20', 'password166', 6),
('Charlotte Thompson', '9876543212', '[email protected]', '1986-02-13', 'password177', 1),
('Oliver White', '4567891232', '[email protected]', '1993-10-07', 'password188', 13),
('Abigail Brown', '7894561233', '[email protected]', '1988-03-28', 'password199', 4),
('Lucas Davis', '3456789014', '[email protected]', '1991-11-15', 'password200', 11),
('Emily Miller', '5678901236', '[email protected]', '1994-04-09', 'password211', 16),
('Logan Johnson', '9012345670', '[email protected]', '1987-07-22', 'password222', 9),
('Grace Carter', '2345678903', '[email protected]', '1995-01-16', 'password233', 7),
('Henry Smith', '6789012347', '[email protected]', '1990-09-05', 'password244', 14),
('Amelia Anderson', '8901234569', '[email protected]', '1991-02-28', 'password255', 19),
('Ethan Wilson', '1234567893', '[email protected]', '1993-11-13', 'password266', 20);
INSERT INTO Passenger (PassengerName, PassengerNumber, PassengerEmail, PassengerDOB, DiscountPassID, AssociatedWith) VALUES
('John Doe', '1234667890', '[email protected]', '1990-01-01', 1, 1),
('Jane Smith', '9876548211', '[email protected]', '1992-02-02', 2, 2),
('Michael Johnson', '1357944681', '[email protected]', '1988-03-03', 3, 3),
('Emily Brown', '2468077572', '[email protected]', '1995-04-04', 3, 4),
('David Lee', '5678901735', '[email protected]', '1985-05-05', 1, 5),
('Olivia Miller', '4371098766', '[email protected]', '1998-06-06', 2, 6),
('William Taylor', '7890723457', '[email protected]', '1982-07-07', 3, 7),
('Sophia Anderson', '3579746812', '[email protected]', '2000-08-08', 1, 8),
('James Wilson', '6105273848', '[email protected]', '1979-09-09', 2, 9),
('Ava White', '924683973', '[email protected]', '2002-10-10', 3, 10),
('Benjamin Hall', '7472583692', '[email protected]', '1986-11-11', 1, 11),
('Charlotte Clark', '8569014726', '[email protected]', '1999-12-12', 2, 12),
('Thomas Harris', '2585690148', '[email protected]', '1983-01-13', 3, 13),
('Amelia Jones', '9014525837', '[email protected]', '2001-02-14', 1, 14),
('Ethan Carter', '4725536903', '[email protected]', '1978-03-15', 2, 15),
('Grace Miller', '2583590149', '[email protected]', '2003-04-16', 3, 16),
('Noah Davis', '8369015727', '[email protected]', '1985-05-17', 1, 17),
('Mia Rodriguez', '1475583694', '[email protected]', '1997-06-18', 2, 18),
('Oliver Martinez', '5536901473', '[email protected]', '1981-07-19', 3, 19),
('Lily Hernandez', '3650147259', '[email protected]', '2000-08-20', 1, 20);
INSERT INTO Admin (username, password) VALUES
('SystemAdmin', 'securePass123'),
('NetworkMaster', 'adminSecure456'),
('DatabaseGuardian', 'passwordMaster789'),
('AppController', 'secureAppAccess'),
('ServerSupervisor', 'superSecurePass'),
('SecurityOfficer', 'adminSecurity123'),
('DataAnalystLead', 'dataSecure456'),
('CloudEngineer', 'cloudPass789'),
('ITManager', 'itAdmin123'),
('DevOpsLead', 'devOpsSecure456'),
('SystemArchitect', 'architectPass789'),
('NetworkSpecialist', 'networkAdmin123'),
('DatabaseExpert', 'dbExpertSecure456'),
('AppDeveloper', 'appDevPass789'),
('ServerTechnician', 'serverTech123'),
('SecurityAnalyst', 'securityAnalyst456'),
('DataScientist', 'dataScientistPass789'),
('CloudArchitect', 'cloudArch123'),
('ITSupportLead', 'itSupportSecure456');