jeremy
jeremy

Reputation: 15

Unable to create table oracle?

I am unable to create this table in oracle and keep getting the error ORA-00942: table or view does not exist any help much appreciated!

CREATE TABLE Occupancy 
(
  PatientNo          CHAR(6),
  WardNo             CHAR(6),
  BedNo              NUMBER(2),
  StartOfOccupancy   DATE,
  EndOfOccupancy     DATE,
  CostsIncurred      NUMBER(6,2),
  PRIMARY KEY (Patientno,WardNo,BedNo,StartOfOccupancy),
  FOREIGN KEY (Patientno) REFERENCES Patient (PatientNo),
  FOREIGN KEY (WardNo,BedNo) REFERENCES Bed (WardNo,BedNo)
)

Upvotes: 0

Views: 1712

Answers (1)

Anjan Biswas
Anjan Biswas

Reputation: 7912

The tables Patient and Bed doesn't exist in the schema (or do not have a public synonym) where you are trying to create Table Occupancy. If they do exist in a different schema use SCHEMA_NAME.Patient and SCHEMA_NAME.Bed in the create statement, or create a public synonym for the two tables Patient and Bed. If you have privileges to reference those tables the new table should get created, otherwise the REFERENCES needs to be granted to your schema as

GRANT REFERENCES (PatientNo)
ON SCHEMA_NAME.Patient
TO YOUR_SCHEMA;

And

GRANT REFERENCES (WardNo,BedNo)
ON SCHEMA_NAME.Bed
TO YOUR_SCHEMA;

Upvotes: 1

Related Questions