Search code examples
sqloracle-databaseidentifier

The code below is showing error of invalid identifier in oracle


create table productinfotwo
(
productId number(10),
CONSTRAINT primary_pk Primary Key(productId),
productname varchar2(100),
SUBCATEGORYID number(10),
CONSTRAINT subcategory_fk Foreign Key(SUBCATEGORYID ) REFERENCES ProductSubCategory(SUBCATEGORYID ), 
COMPANYID varchar2(20), 
CONSTRAINT company_fk Foreign Key(COMPANYID ) References CompanyInfo(COMPANYID ),
price float,
quantity number(10),
description varchar2(1000),
);

Solution

  • You need to have them in order

    1. Create ProductSubCategory table
    2. Create CompanyInfo table
    3. There is no datatype called float in Oracle. You can use NUMBER(4,2) instead
    4. Remove the comma after description

    The code should be

    CREATE TABLE productinfotwo 
      ( 
         productid     NUMBER(10), 
              CONSTRAINT primary_pk PRIMARY KEY(productid), 
              productname   VARCHAR2(100), 
              subcategoryid NUMBER(10), 
              CONSTRAINT subcategory_fk FOREIGN KEY(subcategoryid ) REFERENCES 
              productsubcategory(subcategoryid ), 
              companyid     VARCHAR2(20), 
              CONSTRAINT company_fk FOREIGN KEY(companyid ) REFERENCES companyinfo( 
              companyid ), 
         price         NUMBER(4, 2), 
         quantity      NUMBER(10), 
         description   VARCHAR2(1000) 
      );