I am using Oracle SQL developer to create a basic table with the following command:
CREATE TABLE chartered_flight(
flight_no NUMBER(4) PRIMARY KEY
, customer_id FOREIGN KEY
, aircraft_no FOREIGN KEY
, flight_type VARCHAR2 (12)
, flight_date DATE NOT NULL
, flight_time TO_DATE 'HH:MI' NOT NULL
, takeoff_at CHAR (3) NOT NULL
, destination CHAR (3) NOT NULL
)
Where is the missing right parenthesis? Or is the syntax that I have used incorrect.
I have made the following changes:
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)
Now I get this error:
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:
I have a feeling it is something to do with TO_DATE or is it because I have not created my aircraft table yet so aircraft_no is missing? Can some one please help, thanks.
To specify foreign key constraint, you should either use inline
customer_id [type] REFERENCES [master_table_name]([master_column_name])or out of line syntax :, CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name])See more example here. Also, it usually makes sense to add indexes on foreign key columns.For flight_time you probably need to use
INTERVAL DAY TO SECONDtype