0
votes

Using Oracle Database 11g Express Edition

This Creates my Car_Asset Table:

CREATE TABLE Car_Asset

(Car_No SMALLINT,

Registration_No CHAR(16),

Mileage INTEGER,

Date_MOT_Due  DATE,

Condition  VARCHAR(20),

CONSTRAINT car_pk PRIMARY KEY (Car_No,Registration_No));

This Creates my Insurer Table:

CREATE TABLE Insurer

(Insurer_No SMALLINT,

Insurer_Name VARCHAR(50),

Insurer_Address VARCHAR(100),

CONSTRAINT ins_pk PRIMARY KEY (Insurer_No));

I want to add the Insurer_No as a foreign key in the Car_Asset Table

this is where I get the ORA-00904: "INSURER_NO": invalid identifier:

ALTER TABLE Car_Asset

ADD CONSTRAINT Car_Ins_fk 

FOREIGN KEY (Insurer_No) 

REFERENCES Insurer(Insurer_No);
1

1 Answers

3
votes

Adding the constraint doesn't add the column. So either add Insurer_No to the table or use alter table:

alter table add insurer_no smallint;

Then you can add the constraint.