我正在尝试在 Oracle 中创建一个表并收到错误:ORA-00904: : invalid identifier
这是我的命令。我真的看不出有什么问题。请帮我找出错误。谢谢。

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);

最佳答案

如前所述,将“日期”更改为更具描述性而非保留的内容。此外,似乎 TINYINT 在创建表中不起作用,因此将其更改为 NUMBER(1),以及 Tony 减小名称大小的正确建议 (

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
);

关于sql - ORA-00904: : 无效标识符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4452671/

10-10 23:40