CREATE TABLE chartered flight(flight_no NUMBER(4) PRIMARY KEY
, customer_id NUMBER(6) REFERENCES customer(customer_id)
, aircraft_no NUMBER(4) REFERENCES aircraft(aircraft_no)
, flight_type VARCHAR2 (12)
, flight_date DATE NOT NULL
, flight_time INTERVAL DAY TO SECOND NOT NULL
, takeoff_at CHAR (3) NOT NULL
, destination CHAR (3) NOT NULL)
Should I not use CHAR data type?
I hear it is bad practice to use it but I wanted to make it so takeoff_at and destination have to have minimum 3 characters because they are airport codes.
This is the error I am getting:
Error at Command Line:1 Column:23
Error report:
SQL Error: ORA-00922: missing or invalid option
00922. 00000 - "missing or invalid option"
*Cause:
*Action:
The error you’re getting appears to be the result of the fact that there is no underscore between “chartered” and “flight” in the table name. I assume you want something like this where the name of the table is
chartered_flight.Generally, there is no benefit to declaring a column as
CHAR(3)rather thanVARCHAR2(3). Declaring a column asCHAR(3)doesn’t force there to be three characters of (useful) data. It just tells Oracle to space-pad data with fewer than three characters to three characters. That is unlikely to be helpful if someone inadvertently enters an incorrect code. Potentially, you could declare the column asVARCHAR2(3)and then add aCHECKconstraint thatLENGTH(takeoff_at) = 3.Since both
takeoff_atanddestinationare airport codes, you really ought to have a separate table of valid airport codes and define foreign key constraints between thechartered_flighttable and this newairport_codetable. That ensures that only valid airport codes are added and makes it much easier in the future if an airport code changes.And from a naming convention standpoint, since both
takeoff_atanddestinationare airport codes, I would suggest that the names be complementary and indicate that fact. Something likedeparture_airport_codeandarrival_airport_code, for example, would be much more meaningful.