-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBMS_G005_DDL_Raj_RailwaysBookingSystem.sql
146 lines (103 loc) · 2.98 KB
/
DBMS_G005_DDL_Raj_RailwaysBookingSystem.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
drop database if exists railway;
create database railway;
drop table if exists User;
create table User(
Username varchar(255) Primary Key NOT NULL,
Name varchar(255) NOT NULL,
Address varchar(255) NOT NULL,
DOB varchar(255) NOT NULL,
Age int(10) NOT NULL,
Mobile_no INT NOT NULL,
Gender varchar(255) NOT NULL
);
drop table if exists Class;
create table Class(
Train_No int(50) NOT NULL Primary Key,
Class_type varchar(255) NOT NULL,
Fare_Rs int(50) NOT NULL
);
drop table if exists ticket;
create table Ticket(
Username varchar(255) NOT NULL,
PNR_NO bigint Primary Key NOT NULL,
Train_No int(10) NOT NULL,
Train_Name varchar(255) NOT NULL,
Date_Time Datetime NOT NULL,
Passenger_name varchar(255) NOT NULL,
Class varchar(225) NOT NULL,
Source varchar(255) NOT NULL,
Destination varchar(255) NOT NULL,
Date_of_Boarding date,
Coach_no varchar(255) NOT NULL,
Seat_no int(10) NOT NULL
);
drop table if exists Train;
CREATE TABLE Train (
TrainNumber INT PRIMARY KEY,
TrainName VARCHAR(255),
Source VARCHAR(255),
Destination VARCHAR(255),
ArrivalTime TIME,
DepartureTime TIME,
DistanceKms INT
);
alter table train
change ArrivalTime Scheduled_Arrival Time;
alter table train
change DepartureTime Scheduled_Departure Time;
drop table if exists Payments;
CREATE TABLE Payments (
Username varchar(255) NOT NULL,
transaction_id VARCHAR(15),
account_number VARCHAR(11),
passenger_name VARCHAR(50),
bank_name VARCHAR(50),
amount DECIMAL(10, 2)
);
drop table if exists Routes;
CREATE TABLE Routes (
TrainNumber VARCHAR(255) Primary Key,
Via VARCHAR(255),
Max_Time_Halt TIME,
Min_Time_Halt TIME,
Distancekms INT
);
ALTER TABLE Ticket
ADD CONSTRAINT FK_Train_No
FOREIGN KEY (Train_No)
REFERENCES Train (TrainNumber);
ALTER TABLE Ticket
ADD CONSTRAINT FK_user
FOREIGN KEY (Username) REFERENCES User(Username);
ALTER TABLE Ticket
ADD CONSTRAINT FK_trainno
FOREIGN KEY (Train_No) REFERENCES Train(TrainNumber);
Alter table Class
modify Train_No int Not Null Primary Key;
ALTER TABLE Class
ADD CONSTRAINT FK_class
FOREIGN KEY (Train_No) REFERENCES Train(TrainNumber);
ALTER TABLE Routes
ADD CONSTRAINT FK_trainroutes
FOREIGN KEY (TrainNumber) REFERENCES Train(TrainNumber);
ALTER TABLE Payments
ADD CONSTRAINT FK_username
FOREIGN KEY (Username) REFERENCES User(Username);
CREATE VIEW RouteInfo AS
SELECT TrainNumber, Via, Max_Time_Halt, Min_Time_Halt
FROM Routes;
CREATE VIEW PassengerInfo AS
SELECT Username, Name, Address, Age, Gender
FROM User;
CREATE VIEW current_train_status AS
SELECT TrainNumber, TrainName, Source, Scheduled_Departure, Destination, Scheduled_Arrival
FROM train
WHERE Scheduled_Departure > CURRENT_TIME;
CREATE VIEW current_train_status AS
SELECT TrainNumber, TrainName, Source, Scheduled_Departure, Destination, Scheduled_Arrival
FROM train
WHERE Scheduled_Departure > CURRENT_TIME;
CREATE VIEW all_late_trains AS
SELECT TrainNumber, TrainName, Source, Scheduled_Departure, Destination, Scheduled_Arrival
FROM train
WHERE Scheduled_Arrival < CURRENT_TIME;