I am creating a sample IRTC database that includes tables ticket
and train_ticket_fare
. I created a table ticket
with a column as
ticket_class varchar(6)
.
In the table train_ticket_fare
, I referenced it using this
ticket_class references ticket
.
I re-created the tables to check but couldn't find the error.
SQL> desc ticket
Name Null? Type
----------------------- -------- ----------------
PNR_NO NOT NULL NUMBER(10)
TRANSACTIONID NUMBER(10)
FROM_STATION VARCHAR2(20)
TO_STATION VARCHAR2(20)
DATE_OF_JOURNEY DATE
TICKET_CLASS VARCHAR2(6) //this
DATE_OF_BOOKING DATE
TICKET_FARE NUMBER(8,2)
TRAIN_NUMBER NUMBER(5)
SQL> create table Train_Ticket_fare
2 (
3 train_number references train,
4 ticket_class references ticket, //this
5 base_fare number(7,2),
6 reservation_charge number(6,2),
7 superfast_charge number(6,2),
8 other_charge number(6,2),
9 tatkal_charge number(6,2),
10 service_tax number(6,2),
11 primary key(train_number, ticket_class)
12 );
Table created.
SQL> desc Train_Ticket_fare
Name Null? Type
----------------------- -------- ----------------
TRAIN_NUMBER NOT NULL NUMBER(5)
TICKET_CLASS NOT NULL NUMBER(10) //this
BASE_FARE NUMBER(7,2)
RESERVATION_CHARGE NUMBER(6,2)
SUPERFAST_CHARGE NUMBER(6,2)
OTHER_CHARGE NUMBER(6,2)
TATKAL_CHARGE NUMBER(6,2)
SERVICE_TAX NUMBER(6,2)
Resolved! Thanks @stickybit. The table Train_ticket_fare
must have TICKET_CLASS
as primary key which is to be referenced to the table Ticket
. I did the opposite and referenced it wrong.