Question

I am trying to create a Table in Oracle and getting the error : ORA-00904: : invalid identifier

Here is my command. I really can't see any problem in it. Please help me to identify the error. Thanks.

CREATE TABLE Sale (
CustomerId INT NOT NULL ,
BarCode INT NOT NULL ,
SalesId INT NOT NULL ,
Date DATE NULL ,
CheckOut TINYINT(1) NULL ,
PRIMARY KEY (CustomerId, BarCode, SalesId) ,
CONSTRAINT fk_Customer_has_Product_Customer
FOREIGN KEY (CustomerId )
REFERENCES Customer (CustomerId )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Customer_has_Product_Product1
FOREIGN KEY (BarCode )
REFERENCES Product (BarCode )
ON DELETE NO ACTION
ON UPDATE NO ACTION);
Was it helpful?

Solution

As previously mentioned, change "DATE" to something more descriptive and not reserved. also, it seems TINYINT does not work in a table create so change that to NUMBER(1), as well as Tony's correct suggestion of reducing the name size (<=30 chrs)

CREATE TABLE Sale
(
    CustomerId INT NOT NULL                    ,
    BarCode    INT NOT NULL                    ,
    SalesId    INT NOT NULL                    ,
    SaleDate DATE NULL                    , --DATE is reserved, changed to SaleDate
    CheckOut number(1) NULL               , --tinyint(1) did not work so changed to number(1)
    PRIMARY KEY( CustomerId, BarCode, SalesId )     ,
    CONSTRAINT fk_SaleCustCusID FOREIGN KEY( CustomerId ) REFERENCES Customer( CustomerId ) ON
    DELETE NO ACTION ON
    UPDATE NO ACTION,
    CONSTRAINT fk_SaleCustBarCode FOREIGN KEY( BarCode ) REFERENCES Product( BarCode ) ON
    DELETE NO ACTION ON
    UPDATE NO ACTION
);

OTHER TIPS

The maximum length for an Oracle identifier is 30 characters. These exceed that, are 32 chars long:

  • fk_Customer_has_Product_Customer
  • fk_Customer_has_Product_Product1

See Schema Object Naming Rules

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top