0% found this document useful (0 votes)
14 views29 pages

20mis0415 DBMS Lab Da 1

Uploaded by

Thulasi Madhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views29 pages

20mis0415 DBMS Lab Da 1

Uploaded by

Thulasi Madhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

SWE1004 LAB CYCLE SHEET– DATABASE MANAGEMENT

SYSTEMS
LAB ASSIGNMENT-I
NAME: THULASI MADHAN R
REGNO: 20MIS0415
Faculty: JAYARAM REDDY A
Slot: L3+L4

Railway Reservation System - (Redesigning IRCTC database)


CREATING TABLES:
TRAIN:
Create Table Train(Train_Number NUMBER(7), constraint Train_Train_Number_pk primary
key(Train_Number), Train_Name VARCHAR(20), Source VARCHAR(20), Destination VARCHAR(20), Start_Time
TIMESTAMP, Reach_Time TIMESTAMP, Travel_Time_Hours NUMBER(10), Distance_Kms NUMBER(5),
Class_type VARCHAR(10), Days VARCHAR(7) );

TICKET:
Create Table Ticket(PNR_NO NUMBER(10), constraint
Ticket_PNR_NO_pk primary key(PNR_NO), Transaction_Id NUMBER(15),
From_Station VARCHAR(20), To_Station VARCHAR(20), Date_Of_Journey
DATE, Class VARCHAR(20), Date_Of_Booking DATE, Total_Fare
NUMBER(6), Train_Number Number(7) constraint Ticket_Train_Number_fk REFERENCES
Train(Train_Number));

PASSANGER:
Create Table Passenger(PNR_NO NUMBER(10), Serial_No
NUMBER(20), Name VARCHAR(30), Age NUMBER(2), Reservation_Status
VARCHAR(10), constraint Passenger_PNR_NO_fk foreign key(PNR_NO) REFERENCES Ticket(PNR_NO),
constraint Passenger_pk primary key(PNR_NO,Serial_No));
TRAIN ROUTE:
Create Table Train_Route(Train_Number NUMBER(7), Route_No
NUMBER(20), Station_Code VARCHAR(20), Train_Name VARCHAR(30),
Arrival_Time Timestamp, Depart_Time Timestamp, Distance_Kms NUMBER(10), Days VARCHAR(10),
constraint Train_Route_pk primary key(Train_Number,Route_No), constraint
Train_Route_train_Number foreign key(Train_Number) REFERENCES Train(Train_Number));

TRAIN TICKET FARE:


Create Table Train_Ticket_Fare(Train_Number NUMBER(7), Class
VARCHAR(20), Base_Fare NUMBER(10), Reservation_Charge NUMBER(10),
Superfast_Charge NUMBER(10), Other_Charge NUMBER(10), Tatkal_Charge NUMBER(10),
Service_Tax NUMBER(10), constraint Train_Ticket_Fare_pk primary key(Train_Number,Class),
constraint Train_Ticket_Fare_Train_Number foreign key(Train_Number) REFERENCES
Train(Train_Number));
CREATING ROWS:
TRAINS
> Insert Into Train Values(&Train_Number, &Train_Name,

2 &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

3 &Distance_kms, &Class_Type, &Days, &Type);

Enter value for train_number: 124536

Enter value for train_name: 'Kerala Express'

old 1: Insert Into Train Values(&Train_Number, &Train_Name,

new 1: Insert Into Train Values(124536, 'Kerala Express',

Enter value for source: 'Kerala'

Enter value for destination: 'Vellore'

Enter value for start_time: '02-sep-22 07:15:00 am'

Enter value for reach_time: '03-sep-22 04:00:00 am'

Enter value for travel_time_hours: 600

old 2: &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

new 2: 'Kerala', 'Vellore', '02-sep-22 07:15:00 am', '03-sep-22 04:00:00 am', 600,

Enter value for distance_kms: 600

Enter value for class_type: 'Normal'

Enter value for days: 'Tuesday'

Enter value for type: 'Superfast'

old 3: &Distance_kms, &Class_Type, &Days, &Type)

new 3: 600, 'Normal', 'Tuesday', 'Superfast')

1 row created.

SQL> Insert Into Train Values(&Train_Number, &Train_Name,

2 &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

3 &Distance_kms, &Class_Type, &Days, &Type);

Enter value for train_number: 67890

Enter value for train_name: 'Vikram Express'

old 1: Insert Into Train Values(&Train_Number, &Train_Name,

new 1: Insert Into Train Values(67890, 'Vikram Express',


Enter value for source: 'AP'

Enter value for destination: 'Knniyakumari'

Enter value for start_time: '05-sep-22 07:15:00 am'

Enter value for reach_time: '07-sep-22 07:15:00 am'

Enter value for travel_time_hours: 30

old 2: &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

new 2: 'AP', 'Knniyakumari', '05-sep-22 07:15:00 am', '07-sep-22 07:15:00 am', 30,

Enter value for distance_kms: 1000

Enter value for class_type: 'Sleepers'

Enter value for days: 'Monday'

Enter value for type: 'Fast'

old 3: &Distance_kms, &Class_Type, &Days, &Type)

new 3: 1000, 'Sleepers', 'Monday', 'Fast')

1 row created.

SQL> Insert Into Train Values(&Train_Number, &Train_Name,

2 &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

3 &Distance_kms, &Class_Type, &Days, &Type);

Enter value for train_number: 45678

Enter value for train_name: 'Sun Express'

old 1: Insert Into Train Values(&Train_Number, &Train_Name,

new 1: Insert Into Train Values(45678, 'Sun Express',

Enter value for source: 'Kanniyakumari'

Enter value for destination: 'Madras'

Enter value for start_time: '05-oct-22 07:15:00 am'

Enter value for reach_time: '08-oct-22 07:15:00 am'

Enter value for travel_time_hours: 40

old 2: &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

new 2: 'Kanniyakumari', 'Madras', '05-oct-22 07:15:00 am', '08-oct-22 07:15:00 am', 40,

Enter value for distance_kms: 1200


Enter value for class_type: 'Sleepers'

Enter value for days: 'Sunday'

Enter value for type: 'Superfast'

old 3: &Distance_kms, &Class_Type, &Days, &Type)

new 3: 1200, 'Sleepers', 'Sunday', 'Superfast')

1 row created.

> Insert Into Train Values(&Train_Number, &Train_Name,

2 &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

3 &Distance_kms, &Class_Type, &Days, &Type);

Enter value for train_number: 24563

Enter value for train_name: 'Devil express'

old 1: Insert Into Train Values(&Train_Number, &Train_Name,

new 1: Insert Into Train Values(24563, 'Devil express',

Enter value for source: 'Delhi'

Enter value for destination: 'Vellore'

Enter value for start_time: '05-aug-22 07:15:00 am'

Enter value for reach_time: '08-aug-22 07:15:00 am'

Enter value for travel_time_hours: 45

old 2: &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

new 2: 'Delhi', 'Vellore', '05-aug-22 07:15:00 am', '08-aug-22 07:15:00 am', 45,

Enter value for distance_kms: 1500

Enter value for class_type: 'Sleepers'

Enter value for days: 'Monday'

Enter value for type: 'Superfast'

old 3: &Distance_kms, &Class_Type, &Days, &Type)

new 3: 1500, 'Sleepers', 'Monday', 'Superfast')

1 row created.

SQL> Insert Into Train Values(&Train_Number, &Train_Name,

2 &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

3 &Distance_kms, &Class_Type, &Days, &Type);


Enter value for train_number: 41517

Enter value for train_name: 'Vit Express'

old 1: Insert Into Train Values(&Train_Number, &Train_Name,

new 1: Insert Into Train Values(41517, 'Vit Express',

Enter value for source: 'mumbai'

Enter value for destination: 'Vellore'

Enter value for start_time: '11-aug-22 07:15:00 am'

Enter value for reach_time: '16-aug-22 07:15:00 am'

Enter value for travel_time_hours: 56

old 2: &Source, &Destination, &Start_Time, &Reach_Time, &Travel_Time_Hours,

new 2: 'mumbai', 'Vellore', '11-aug-22 07:15:00 am', '16-aug-22 07:15:00 am', 56,

Enter value for distance_kms: 2000

Enter value for class_type: 'Sleepers'

Enter value for days: 'Friday'

Enter value for type: 'nonstop'

old 3: &Distance_kms, &Class_Type, &Days, &Type)

new 3: 2000, 'Sleepers', 'Friday', 'nonstop')

1 row created.

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------

REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

124536 Kerala Express Kerala Vellore

02-SEP-22 07.15.00.000000 AM

03-SEP-22 04.00.00.000000 AM

600 600 Normal Tuesday Superfast


TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------

REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

67890 Vikram Express AP Knniyakumari

05-SEP-22 07.15.00.000000 AM

07-SEP-22 07.15.00.000000 AM

30 1000 Sleepers Monday Fast

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------

REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

45678 Sun Express Kanniyakumari Madras

05-OCT-22 07.15.00.000000 AM

08-OCT-22 07.15.00.000000 AM

40 1200 Sleepers Sunday Superfast

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------
REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

24563 Devil express Delhi Vellore

05-AUG-22 07.15.00.000000 AM

08-AUG-22 07.15.00.000000 AM

45 1500 Sleepers Monday Superfast

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------

REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

41517 Vit Express mumbai Vellore

11-AUG-22 07.15.00.000000 AM

16-AUG-22 07.15.00.000000 AM

56 2000 Sleepers Friday nonstop

TICKET:

SQL> Insert Into Ticket Values(&PNR_NO, &Transaction_Id,

2 &From_Station, &To_Station, &Date_Of_Journey, &Class,

3 &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number);

Enter value for pnr_no: 23456789

Enter value for transaction_id: 9800700431

old 1: Insert Into Ticket Values(&PNR_NO, &Transaction_Id,

new 1: Insert Into Ticket Values(23456789, 9800700431,


Enter value for from_station: 'Delhi'

Enter value for to_station: 'Vellore'

Enter value for date_of_journey: '05-AUG-22'

Enter value for class: 'Sleeper'

old 2: &From_Station, &To_Station, &Date_Of_Journey, &Class,

new 2: 'Delhi', 'Vellore', '05-AUG-22', 'Sleeper',

Enter value for date_of_booking: '03-JUL-22'

Enter value for total_ticket_fare: 400

Enter value for train_number: 24563

old 3: &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number)

new 3: '03-JUL-22', 400, 24563)

1 row created.

SQL> Insert Into Ticket Values(&PNR_NO, &Transaction_Id,

2 &From_Station, &To_Station, &Date_Of_Journey, &Class,

3 &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number);

Enter value for pnr_no: 12345678

Enter value for transaction_id: 2001310067

old 1: Insert Into Ticket Values(&PNR_NO, &Transaction_Id,

new 1: Insert Into Ticket Values(12345678, 2001310067,

Enter value for from_station: 'mumbai'

Enter value for to_station: 'Vellore'

Enter value for date_of_journey: '11-AUG-22'

Enter value for class: 'Sleeper'

old 2: &From_Station, &To_Station, &Date_Of_Journey, &Class,

new 2: 'mumbai', 'Vellore', '11-AUG-22', 'Sleeper',

Enter value for date_of_booking: '02-jul-22'

Enter value for total_ticket_fare: 700

Enter value for train_number: 41517

old 3: &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number)

new 3: '02-jul-22', 700, 41517)

1 row created.
SQL> Insert Into Ticket Values(&PNR_NO, &Transaction_Id,
2 &From_Station, &To_Station, &Date_Of_Journey, &Class,
3 &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number);
Enter value for pnr_no: 98765432
Enter value for transaction_id: 10003445679
old 1: Insert Into Ticket Values(&PNR_NO, &Transaction_Id,
new 1: Insert Into Ticket Values(98765432, 10003445679,
Enter value for from_station: 'kerala'
Enter value for to_station: 'Vellore'
Enter value for date_of_journey: '02-SEP-22'
Enter value for class: 'Normal'
old 2: &From_Station, &To_Station, &Date_Of_Journey, &Class,
new 2: 'kerala', 'Vellore', '02-SEP-22', 'Normal',
Enter value for date_of_booking: '02-AUG-22'
Enter value for total_ticket_fare: 900
Enter value for train_number: 124536
old 3: &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number)
new 3: '02-AUG-22', 900, 124536)

1 row created.

SQL> Insert Into Ticket Values(&PNR_NO, &Transaction_Id,


2 &From_Station, &To_Station, &Date_Of_Journey, &Class,
3 &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number);
Enter value for pnr_no: 65748943
Enter value for transaction_id: 3000987642
old 1: Insert Into Ticket Values(&PNR_NO, &Transaction_Id,
new 1: Insert Into Ticket Values(65748943, 3000987642,
Enter value for from_station: 'AP'
Enter value for to_station: 'Knniyakumari'
Enter value for date_of_journey: '05-SEP-22'
Enter value for class: 'Sleeper'
old 2: &From_Station, &To_Station, &Date_Of_Journey, &Class,
new 2: 'AP', 'Knniyakumari', '05-SEP-22', 'Sleeper',
Enter value for date_of_booking: '05-AUG-22'
Enter value for total_ticket_fare: 1500
Enter value for train_number: 67890
old 3: &Date_Of_Booking, &Total_Ticket_Fare, &Train_Number)
new 3: '05-AUG-22', 1500, 67890)

1 row created.

select * from Ticket


2 ;

PNR_NO TRANSACTION_ID FROM_STATION TO_STATION DATE_OF_J


---------- -------------- -------------------- -------------------- ---------
CLASS DATE_OF_B TOTAL_FARE TRAIN_NUMBER
-------------------- --------- ---------- ------------
23456789 9800700431 Delhi Vellore 05-AUG-22
Sleeper 03-JUL-22 400 24563

12345678 2001310067 mumbai Vellore 11-AUG-22


Sleeper 02-JUL-22 700 41517

98765432 1.0003E+10 kerala Vellore 02-SEP-22


Normal 02-AUG-22 900 124536
PNR_NO TRANSACTION_ID FROM_STATION TO_STATION DATE_OF_J
---------- -------------- -------------------- -------------------- ---------
CLASS DATE_OF_B TOTAL_FARE TRAIN_NUMBER
-------------------- --------- ---------- ------------
65748943 3000987642 AP Knniyakumari 05-SEP-22
Sleeper 05-AUG-22 1500 67890

PASSANGER:
SQL> Insert Into Passenger Values(&PNR_NO, &Serial_No,
2 &Name, &Age, &Reservation_Status);
Enter value for pnr_no: 65748943
Enter value for serial_no: 23
old 1: Insert Into Passenger Values(&PNR_NO, &Serial_No,
new 1: Insert Into Passenger Values(65748943, 23,
Enter value for name: 'MAHA'
Enter value for age: 21
Enter value for reservation_status: 'R'
old 2: &Name, &Age, &Reservation_Status)
new 2: 'MAHA', 21, 'R')

1 row created.

SQL> Insert Into Passenger Values(&PNR_NO, &Serial_No,


2 &Name, &Age, &Reservation_Status);
Enter value for pnr_no: 98765432
Enter value for serial_no: 34
old 1: Insert Into Passenger Values(&PNR_NO, &Serial_No,
new 1: Insert Into Passenger Values(98765432, 34,
Enter value for name: 'TARIK'
Enter value for age: 27
Enter value for reservation_status: 'NR'
old 2: &Name, &Age, &Reservation_Status)
new 2: 'TARIK', 27, 'NR')

1 row created.

SQL> Insert Into Passenger Values(&PNR_NO, &Serial_No,


2 &Name, &Age, &Reservation_Status);
Enter value for pnr_no: 12345678
Enter value for serial_no: 75
old 1: Insert Into Passenger Values(&PNR_NO, &Serial_No,
new 1: Insert Into Passenger Values(12345678, 75,
Enter value for name: 'TENZ'
Enter value for age: 28
Enter value for reservation_status: 'R'
old 2: &Name, &Age, &Reservation_Status)
new 2: 'TENZ', 28, 'R')

1 row created.

SQL> Insert Into Passenger Values(&PNR_NO, &Serial_No,


2 &Name, &Age, &Reservation_Status);
Enter value for pnr_no: 23456789
Enter value for serial_no: 45
old 1: Insert Into Passenger Values(&PNR_NO, &Serial_No,
new 1: Insert Into Passenger Values(23456789, 45,
Enter value for name: 'SHROUD'
Enter value for age: 32
Enter value for reservation_status: 'R'
old 2: &Name, &Age, &Reservation_Status)
new 2: 'SHROUD', 32, 'R')

1 row created.

SQL> SELECT*FROM PASSENGER;

PNR_NO SERIAL_NO NAME AGE RESERVATIO


---------- ---------- ------------------------------ ---------- ----------
65748943 23 MAHA 21 R
98765432 34 TARIK 27 NR
12345678 75 TENZ 28 R
23456789 45 SHROUD 32 R

TRAIN ROUTE:
Insert Into Train_Route Values(&Train_NUmber,
2 &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
3 &Distance_Kms, &Days);
Enter value for train_number: 24563
old 1: Insert Into Train_Route Values(&Train_NUmber,
new 1: Insert Into Train_Route Values(24563,
Enter value for route_no: 15
Enter value for station_code: 'DL'
Enter value for train_name: 'dEVIL EXPRESS'
Enter value for arrival_time: '05-AUG-22 07:00:00'
Enter value for depart_time: '05-AUG-22 07:15:00'
old 2: &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
new 2: 15, 'DL', 'dEVIL EXPRESS', '05-AUG-22 07:00:00', '05-AUG-22 07:15:00',
Enter value for distance_kms: 1500
Enter value for days: 'MONDAY'
old 3: &Distance_Kms, &Days)
new 3: 1500, 'MONDAY')

1 row created.

SQL> Insert Into Train_Route Values(&Train_NUmber,


2 &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
3 &Distance_Kms, &Days);
Enter value for train_number: 67890
old 1: Insert Into Train_Route Values(&Train_NUmber,
new 1: Insert Into Train_Route Values(67890,
Enter value for route_no: 12
Enter value for station_code: 'AP'
Enter value for train_name: 'VIKRAM EXPRESS'
Enter value for arrival_time: '05-SEP-22 07:00:00'
Enter value for depart_time: '05-SEP-22 07:15:00'
old 2: &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
new 2: 12, 'AP', 'VIKRAM EXPRESS', '05-SEP-22 07:00:00', '05-SEP-22 07:15:00',
Enter value for distance_kms: 1000
Enter value for days: 'MONDAY'
old 3: &Distance_Kms, &Days)
new 3: 1000, 'MONDAY')

1 row created.

SQL> Insert Into Train_Route Values(&Train_NUmber,


2 &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
3 &Distance_Kms, &Days);
Enter value for train_number: 124536
old 1: Insert Into Train_Route Values(&Train_NUmber,
new 1: Insert Into Train_Route Values(124536,
Enter value for route_no: 3
Enter value for station_code: 'KR'
Enter value for train_name: 'KERALA EXPRESS'
Enter value for arrival_time: '02-SEP-22 07:00:00'
Enter value for depart_time: '02-SEP-22 07:20:00'
old 2: &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
new 2: 3, 'KR', 'KERALA EXPRESS', '02-SEP-22 07:00:00', '02-SEP-22 07:20:00',
Enter value for distance_kms: 600
Enter value for days: 'TUESDAY'
old 3: &Distance_Kms, &Days)
new 3: 600, 'TUESDAY')

1 row created.

SQL> Insert Into Train_Route Values(&Train_NUmber,


2 &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
3 &Distance_Kms, &Days);
Enter value for train_number: 41517
old 1: Insert Into Train_Route Values(&Train_NUmber,
new 1: Insert Into Train_Route Values(41517,
Enter value for route_no: 5
Enter value for station_code: 'MV'
Enter value for train_name: 'VIT EXPRESS'
Enter value for arrival_time: '11-AUG-22 07:00:00'
Enter value for depart_time: '11-AUG-22 07:30:00'
old 2: &Route_No, &Station_Code, &Train_Name, &Arrival_Time, &Depart_Time,
new 2: 5, 'MV', 'VIT EXPRESS', '11-AUG-22 07:00:00', '11-AUG-22 07:30:00',
Enter value for distance_kms: 2000
Enter value for days: 'FRIDAY'
old 3: &Distance_Kms, &Days)
new 3: 2000, 'FRIDAY')

1 row created.

SQL> SELECT * FROM TRAIN_ROUTE;

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME


------------ ---------- -------------------- ------------------------------
ARRIVAL_TIME
---------------------------------------------------------------------------
DEPART_TIME
---------------------------------------------------------------------------
DISTANCE_KMS DAYS
------------ ----------
24563 15 DL dEVIL EXPRESS
05-AUG-22 07.00.00.000000 AM
05-AUG-22 07.15.00.000000 AM
1500 MONDAY

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME


------------ ---------- -------------------- ------------------------------
ARRIVAL_TIME
---------------------------------------------------------------------------
DEPART_TIME
---------------------------------------------------------------------------
DISTANCE_KMS DAYS
------------ ----------
67890 12 AP VIKRAM EXPRESS
05-SEP-22 07.00.00.000000 AM
05-SEP-22 07.15.00.000000 AM
1000 MONDAY

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME


------------ ---------- -------------------- ------------------------------
ARRIVAL_TIME
---------------------------------------------------------------------------
DEPART_TIME
---------------------------------------------------------------------------
DISTANCE_KMS DAYS
------------ ----------
124536 3 KR KERALA EXPRESS
02-SEP-22 07.00.00.000000 AM
02-SEP-22 07.20.00.000000 AM
600 TUESDAY

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME


------------ ---------- -------------------- ------------------------------
ARRIVAL_TIME
---------------------------------------------------------------------------
DEPART_TIME
---------------------------------------------------------------------------
DISTANCE_KMS DAYS
------------ ----------
41517 5 MV VIT EXPRESS
11-AUG-22 07.00.00.000000 AM
11-AUG-22 07.30.00.000000 AM
2000 FRIDAY

TRAIN TICKET FARE:


Insert Into Train_Ticket_Fare Values(&Train_Number,
2 &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
3 &Other_Charge, &Tatkal_Charge, &Service_Tax);
Enter value for train_number: 124536
old 1: Insert Into Train_Ticket_Fare Values(&Train_Number,
new 1: Insert Into Train_Ticket_Fare Values(124536,
Enter value for class: 'NORMAL'
Enter value for base_fare: 400
Enter value for reservation_charge: 50
Enter value for superfast_charge: 560
old 2: &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
new 2: 'NORMAL', 400, 50, 560,
Enter value for other_charge: 90
Enter value for tatkal_charge: 780
Enter value for service_tax: 99
old 3: &Other_Charge, &Tatkal_Charge, &Service_Tax)
new 3: 90, 780, 99)

1 row created.

SQL> Insert Into Train_Ticket_Fare Values(&Train_Number,


2 &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
3 &Other_Charge, &Tatkal_Charge, &Service_Tax);
Enter value for train_number: 67890
old 1: Insert Into Train_Ticket_Fare Values(&Train_Number,
new 1: Insert Into Train_Ticket_Fare Values(67890,
Enter value for class: 'SLEEPER'
Enter value for base_fare: 500
Enter value for reservation_charge: 40
Enter value for superfast_charge: 890
old 2: &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
new 2: 'SLEEPER', 500, 40, 890,
Enter value for other_charge: 70
Enter value for tatkal_charge: 600
Enter value for service_tax: 99
old 3: &Other_Charge, &Tatkal_Charge, &Service_Tax)
new 3: 70, 600, 99)

1 row created.

SQL> Insert Into Train_Ticket_Fare Values(&Train_Number,


2 &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
3 &Other_Charge, &Tatkal_Charge, &Service_Tax);
Enter value for train_number: 24563
old 1: Insert Into Train_Ticket_Fare Values(&Train_Number,
new 1: Insert Into Train_Ticket_Fare Values(24563,
Enter value for class: 'SLEEPER'
Enter value for base_fare: 800
Enter value for reservation_charge: 250
Enter value for superfast_charge: 780
old 2: &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
new 2: 'SLEEPER', 800, 250, 780,
Enter value for other_charge: 150
Enter value for tatkal_charge: 800
Enter value for service_tax: 199
old 3: &Other_Charge, &Tatkal_Charge, &Service_Tax)
new 3: 150, 800, 199)

1 row created.

SQL> Insert Into Train_Ticket_Fare Values(&Train_Number,


2 &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
3 &Other_Charge, &Tatkal_Charge, &Service_Tax);
Enter value for train_number: 41517
old 1: Insert Into Train_Ticket_Fare Values(&Train_Number,
new 1: Insert Into Train_Ticket_Fare Values(41517,
Enter value for class: 'SLEEPERS'
Enter value for base_fare: 1000
Enter value for reservation_charge: 300
Enter value for superfast_charge: 890
old 2: &Class, &Base_Fare, &Reservation_Charge, &Superfast_Charge,
new 2: 'SLEEPERS', 1000, 300, 890,
Enter value for other_charge: 100
Enter value for tatkal_charge: 900
Enter value for service_tax: 299
old 3: &Other_Charge, &Tatkal_Charge, &Service_Tax)
new 3: 100, 900, 299)

1 row created.

SQL> SELECT * FROM TRAIN_TICKET_FARE;

TRAIN_NUMBER CLASS BASE_FARE RESERVATION_CHARGE SUPERFAST_CHARGE


------------ -------------------- ---------- ------------------ ----------------
OTHER_CHARGE TATKAL_CHARGE SERVICE_TAX
------------ ------------- -----------
124536 NORMAL 400 50 560
90 780 99

67890 SLEEPER 500 40 890


70 600 99

24563 SLEEPER 800 250 780


150 800 199

TRAIN_NUMBER CLASS BASE_FARE RESERVATION_CHARGE SUPERFAST_CHARGE


------------ -------------------- ---------- ------------------ ----------------
OTHER_CHARGE TATKAL_CHARGE SERVICE_TAX
------------ ------------- -----------
41517 SLEEPERS 1000 300 890
100 900 299

Use ADT(varray) for class and days:


For Class
CODE:
CREATE Or REPLACE TYPE Class_type AS VARRAY(3) OF VARCHAR(20);
2 /
Type created.

For DAYS
CODE:
CREATE Or REPLACE TYPE Days_type AS VARRAY(7) OF VARCHAR(20);
2 /
Type created.
2. Write simple DDL/DML Queries
a) Remove all the rows from Passenger table permanently.

SQL >DELETE FROM Passenger


5 rows deleted
b) Change the name of the Passenger table to Passenger_Details
SQL> RENAME Passenger to Passenger_details;
Table renamed.
SQL> DESC PASSENGER_DETAILS;
Name Null? Type
----------------------------------------- -------- ----------------------------
PNR_NO NOT NULL NUMBER(10)
SERIAL_NO NOT NULL NUMBER(20)
NAME VARCHAR2(30)
AGE NUMBER(2)
RESERVATION_STATUS VARCHAR2(10)

c) List all train details

SELECT *FROM TRAIN;

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION


------------ -------------------- -------------------- --------------------
START_TIME
---------------------------------------------------------------------------
REACH_TIME
---------------------------------------------------------------------------
TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE
----------------- ------------ --------------- ------- ---------------
24563 Devil express Delhi Vellore
05-AUG-22 07.15.00.000000 AM
08-AUG-22 07.15.00.000000 AM
45 1500 Sleepers Monday Superfast

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION


------------ -------------------- -------------------- --------------------
START_TIME
---------------------------------------------------------------------------
REACH_TIME
---------------------------------------------------------------------------
TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE
----------------- ------------ --------------- ------- ---------------
41517 Vit Express mumbai Vellore
11-AUG-22 07.15.00.000000 AM
16-AUG-22 07.15.00.000000 AM
56 2000 Sleepers Friday nonstop

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION


------------ -------------------- -------------------- --------------------
START_TIME
---------------------------------------------------------------------------
REACH_TIME
---------------------------------------------------------------------------
TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE
----------------- ------------ --------------- ------- ---------------
124536 Kerala express kerala vellore
02-SEP-22 07.15.00.000000 AM
03-SEP-22 07.15.00.000000 AM
12 600 Normal Tuesday Superfast

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION


------------ -------------------- -------------------- --------------------
START_TIME
---------------------------------------------------------------------------
REACH_TIME
---------------------------------------------------------------------------
TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE
----------------- ------------ --------------- ------- ---------------
67890 Vikram express AP vellore
05-SEP-22 07.15.00.000000 AM
06-SEP-22 07.15.00.000000 AM
22 700 Sleepers Monday superfast

d) List all passenger details

SELECT *FROM passenger_details;

PNR_NO SERIAL_NO NAME AGE RESERVATIO

---------- ---------- ------------------------------ ---------- ----------

65748943 23 MAHA 21 R

98765432 34 TARIK 27 NR

12345678 75 TENZ 28 R

23456789 45 SHROUD 32 R

e) Give a list of trains in ascending order of number.


SQL> Select Train_Number, Train_Name From Train ORDER BY

2 Train_number ASC;

TRAIN_NUMBER TRAIN_NAME

------------ --------------------

24563 Devil express

41517 Vit Express

67890 Vikram express

124536 Kerala express


f) List the senior citizen passenger details.
Select*From Passenger_details WHERE Age>=60;

no rows selected

SQL> Select*From Passenger_details WHERE Age>=50;

no rows selected

Select*From Passenger_details WHERE Age>=30;

PNR_NO SERIAL_NO NAME AGE RESERVATIO

---------- ---------- ------------------------------ ---------- ----------

23456789 45 SHROUD 32 R

g) List the station names where code starts with 'M'.


SQL> Select Train_Name From Train_Route WHERE Station_Code='M*';

no rows selected

h) List the train details within a range of numbers.

Select*From Train WHERE Train_Number>=15000 and

2 Train_Number<=35000;

TRAIN_NUMBER TRAIN_NAME SOURCE DESTINATION

------------ -------------------- -------------------- --------------------

START_TIME

---------------------------------------------------------------------------

REACH_TIME

---------------------------------------------------------------------------

TRAVEL_TIME_HOURS DISTANCE_KMS CLASS_TYPE DAYS TYPE

----------------- ------------ --------------- ------- ---------------

24563 Devil express Delhi Vellore

05-AUG-22 07.15.00.000000 AM

08-AUG-22 07.15.00.000000 AM

45 1500 Sleepers Monday Superfast


i)Change the superfast charge value in train fare as zero, if it is null.
SQL> Update Train_Ticket_Fare SET Superfast_Charge=0 WHERE

2 Superfast_Charge IS NULL;

0 rows updated.

j) List the passenger names whose tickets are not confirmed


SQL> Select*From Passenger_details WHERE Reservation_status='NR';

PNR_NO SERIAL_NO NAME AGE RESERVATIO

---------- ---------- ------------------------------ ---------- ----------

98765432 34 TARIK 27 NR

K) List the base_fare of all AC coaches available in each train


SQL> Select Base_Fare From Train_Ticket_Fare WHERE Class='SLEEPER';

BASE_FARE

----------

800

500

Find the ticket details where transaction id is not known.


SQL> Select*From Ticket where Transaction_Id=NULL;

no rows selected

i) Use interactive update for updating the seat no for a particular PNR_NO.
SQL> Update Passenger_details SET Serial_No=&Serial_No WHERE

2 Pnr_No=&Pnr_No;

Enter value for serial_no: 45

old 1: Update Passenger_details SET Serial_No=&Serial_No WHERE

new 1: Update Passenger_details SET Serial_No=45 WHERE

Enter value for pnr_no: 23456789

old 2: Pnr_No=&Pnr_No

new 2: Pnr_No=23456789

1 row updated.

SQL> SELECT * FROM PASSENGER_DETAILS;


PNR_NO SERIAL_NO NAME AGE RESERVATIO

---------- ---------- ------------------------------ ---------- ----------

65748943 23 MAHA 21 R

98765432 34 TARIK 27 NR

12345678 75 TENZ 28 R

23456789 45 SHROUD 32 R

ii) Find the train names that are from Chennai to Mumbai, but do not have
the source or destination in its name.
SQL> Select Train_Name From Train WHERE Source='Chennai' AND Destination='Mumbai' AND
Train_Name!='*Chennai*Mumbai*' AND Train_Name!='*Mumbai*Chennai*';

no rows selected

iii) Find the train details that are on Thursday.


SQL> Select*From Train WHERE Days='Thrusday';

no rows selected

3. Create (Alter table to add constraint) the necessary foreign keys by


identifying the relationships in the table.
i)Add a suitable constraint to train table to always have train no in the range 10001 to
99999.
SQL> Alter Table Train ADD constraint Train_Train_Number_check check(TRAIN_NUMBER BETWEEN 10001
AND 99999); Table altered.

ii) Add a suitable constraint for the column of station name, so that does not take
duplicates.
SQL> Alter Table Train_Route ADD constraint

Train_Route_Name_Unique unique(Train_Name);

Table altered.

iii) Change the data type of arrival time, depart time (date -> timestamp or timestamp to
date), and do the necessary process for updating the table with new values.
Alter Table Train_Route modify(Arrival_Time date);

Table altered.

SQL> Alter Table Train_Route modify(Depart_Time date);

Table altered.

SQL> SELECT * FROM TRAIN_ROUTE;


TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------

ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS

--------- --------- ------------ ----------

24563 15 DL dEVIL EXPRESS

05-AUG-22 05-AUG-22 1500 MONDAY

67890 12 AP VIKRAM EXPRESS

05-SEP-22 05-SEP-22 1000 MONDAY

124536 3 KR KERALA EXPRESS

02-SEP-22 02-SEP-22 600 TUESDAY

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------

ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS

--------- --------- ------------ ----------

41517 5 MV VIT EXPRESS

11-AUG-22 11-AUG-22 2000 FRIDAY

For Train Number 24563


SQL> Update Train_Route SET Arrival_Time='02-AUG-22' WHERE Train_Number=24563;

1 row updated.

SQL> Update Train_Route SET Depart_Time='02-AUG-22' WHERE Train_Number=24563;

1 row updated.

For Train Number 41517


SQL> Update Train_Route SET Arrival_Time='05-AUG-22' WHERE Train_Number=41517;

1 row updated.

SQL> Update Train_Route SET Depart_Time='30-AUG-22' WHERE TRAIN_NUMBER=41517;

1 row updated.

For Train Number 124536


SQL> Update Train_Route SET Arrival_Time='15-MAY-23' WHERE Train_Number=124536;

1 row updated.

SQL> Update Train_Route SET Depart_Time='15-MAY-23' WHERE Train_Number=124536;

1 row updated.
For Train Number 67890
SQL> Update Train_Route SET Arrival_Time='05-JUL-22' WHERE Train_Number=67890;

1 row updated.

SQL> Update Train_Route SET Depart_Time='30-JUN-22' WHERE

2 Train_Number=67890;

1 row updated.

SQL> Select Arrival_Time, Depart_Time From Train_Route;

ARRIVAL_T DEPART_TI

--------- ---------

02-AUG-22 02-AUG-22

05-JUL-22 30-JUN-22

15-MAY-23 15-MAY-23

05-AUG-22 30-AUG-22

iv) Add a suitable constraint for the class column that it should take values only as 1A, 2A,
3A, SL, C.
Alter Table Train ADD constraint Train_Class_cK1 check(CLASS_TYPE in ('1A','2A','3A','SL','C'));

v) Add a not null constraint for the column distance in train_route.


SQL> Alter Table Train_Route modify Distance_Kms int NOT NULL;
Table altered.
4. Use SQL PLUS functions to
i) Find the passengers whose date of journey is one month from today.
SQL> Select*From Ticket where Date_Of_Journey=sysdate+30;

no rows selected

ii) Print the train names in upper case.


SQL> select upper(Train_Name) from Train;

UPPER(TRAIN_NAME)

--------------------

DEVIL EXPRESS

VIT EXPRESS

KERALA EXPRESS

VIKRAM EXPRESS

iii) Print the passenger names with left padding character


SQL> Select lpad(name,20,'&') from Passenger_details;

LPAD(NAME,20,'&')

--------------------------------------------------------------------------------

&&&&&&&&&&&&&&&&MAHA

&&&&&&&&&&&&&&&TARIK

&&&&&&&&&&&&&&&&TENZ

&&&&&&&&&&&&&&SHROUD

iv) Print the station codes replacing K with M.


SQL> Select replace(Station_Code,'K','M') from Train_Route;

REPLACE(STATION_CODE

--------------------

DL

AP

MR

MV

v) Translate all the LC in class column (Train_fare) to POT and display


SQL> Select translate(Class,'LC','POT') from Train_Ticket_Fare;

TRANSLATE(CLASS,'LC','POT')

--------------------------------------------------------------------------------

SPEEPER

SPEEPERS

SPEEPER

NORMAP

vi) Display the fare details of all trains, if any value is ZERO, print as
NULL value.
SQL> update Train_Ticket_Fare set base_fare=NULL where base_fare=0;

0 rows updated.

SQL> update Train_Ticket_Fare set reservation_charge=NULL where reservation_charge=0;

0 rows updated.

SQL> update Train_Ticket_Fare set superfast_charge=NULL where superfast_charge=0;

0 rows updated.

SQL> update Train_Ticket_Fare set other_charge=NULL where other_charge=0;


0 rows updated.

SQL> update Train_Ticket_Fare set tatkal_charge=NULL where tatkal_charge=0;

0 rows updated.

SQL> update Train_Ticket_Fare set service_tax=NULL where service_tax=0;

0 rows updated.

vii) Print the date_of_jounrney in the format '27th November 2010'.

SQL> Select

2 to_char(to_date(Date_Of_Journey,'DD/mm/yyyy'),'ddth month yyyy')From Ticket;

TO_CHAR(TO_DATE(DATE_OF_JOURNEY,'DD/MM/YYYY'),

----------------------------------------------

05th august 0022

11th august 0022

02nd september 0022

05th september 0022

vii) Find the maximum fare (total fare)


SQL> Select max(Total_Fare )From Ticket;

MAX(TOTAL_FARE)

---------------

1500

ix) Find the average age of passengers in one ticket.


SQL> Select avg(Age) from Passenger_details;

AVG(AGE)

----------

27

x) Find the maximum length of station name available in the database.


SQL> Select max(length(Train_Name))From Train_route;

MAX(LENGTH(TRAIN_NAME))

-----------------------

14

xi) Print the fare amount of the passengers as rounded value.


SQL> select round(total_fare) from Ticket;
ROUND(TOTAL_FARE)

-----------------

400

700

900

1500

xii) Add the column halt time to train route.


SQL> Alter Table Train_Route ADD Halt_Time number(10);

Table altered.

xiii) Update values to it from arrival time and depart time.


SQL> Alter Table Train_Route ADD Halt_Time number(10);

Table altered.

SQL> update Train_route set halt_time=(depart_time-arrival_time);

4 rows updated.

SQL> select * from Train_route;

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------

ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS HALT_TIME

--------- --------- ------------ ---------- ----------

24563 15 DL dEVIL EXPRESS

02-AUG-22 02-AUG-22 1500 MONDAY 0

67890 12 AP VIKRAM EXPRESS

05-JUL-22 30-JUN-22 1000 MONDAY -5

124536 3 KR KERALA EXPRESS

15-MAY-23 15-MAY-23 600 TUESDAY 0


TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------

ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS HALT_TIME

--------- --------- ------------ ---------- ----------

41517 5 MV VIT EXPRESS

05-AUG-22 30-AUG-22 2000 FRIDAY 25

High Level:

xv) Update values to arrival time and depart time using conversion
functions.
SQL> Update Train_Route set Arrival_time=CURRENT_TIMESTAMP;

4 rows updated.

SQL> select * from Train_Route;

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------

ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS HALT_TIME

--------- --------- ------------ ---------- ----------

24563 15 DL dEVIL EXPRESS

27-AUG-22 02-AUG-22 1500 MONDAY 0

67890 12 AP VIKRAM EXPRESS

27-AUG-22 30-JUN-22 1000 MONDAY -5

124536 3 KR KERALA EXPRESS

27-AUG-22 15-MAY-23 600 TUESDAY 0

TRAIN_NUMBER ROUTE_NO STATION_CODE TRAIN_NAME

------------ ---------- -------------------- ------------------------------


ARRIVAL_T DEPART_TI DISTANCE_KMS DAYS HALT_TIME

--------- --------- ------------ ---------- ----------

41517 5 MV VIT EXPRESS

27-AUG-22 30-AUG-22 2000 FRIDAY 25

xvi) Display the arrival time, depart time in the format HH:MI (24 hours
and minutes).
SQL> select to_char(Arrival_time,'HH:MM') from Train_Route;

TO_CH

-----

01:08

01:08

01:08

01:08

SQL> select to_char(Depart_time,'HH:MM') from Train_Route;

TO_CH

-----

12:08

12:06

12:05

12:08

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy