Home > Back-end >  Which keywords did I missed on the following tables?
Which keywords did I missed on the following tables?

Time:11-11

My problem: I get the same error on the tables: Tasks, TimeSheet, TimeSheetHour.

I still don't have any idea on what keywords did I missed.

Here is the error I got in Tasks table: (same with other tables)

May I know which keywords did I missed on the following tables?

-- what keywords did I missed here?
CREATE TABLE Tasks(
    IdTask  NUMBER(10,0) NOT NULL,                  
    IdProject   NUMBER(10,0) NOT NULL,       
    Task_Name   VARCHAR2(100) NOT NULL,    
    Task_Description    VARCHAR2(100),
    StartDate   DATE NOT NULL,
    EndDate DATE NOT NULL,
    CreatedAt VARCHAR2(50),
    UpdatedAt VARCHAR2(50),
    Enabled CHAR(10),
    CONSTRAINT IdTask_PK PRIMARY KEY (IdTask),
    CONSTRAINT IdProject_FK FOREIGN KEY (IdProject) REFERENCE Project_T(IdProject)
);
 

-- what keywords did I missed here?
CREATE TABLE TimeSheet(
    IdTimeSheet NUMBER(10,0) NOT NULL,
    IdUser NUMBER(10,0) NOT NULL,
    IdProject NUMBER(10,0) NOT NULL,
    TimeSheet_Name VARCHAR2(100) NOT NULL,
    TimeSheet_Description VARCHAR2(200),
    CreatedAt VARCHAR2(50),
    UpdatedAt VARCHAR2(50),
    Enabled CHAR(10),
    CONSTRAINT IdTimeSheet_PK PRIMARY KEY (IdTimeSheet),
    CONSTRAINT IdProject_FK FOREIGN KEY (IdProject) REFERENCE Project_T(IdProject),
    CONSTRAINT IdUser_FK FOREIGN KEY (IdUser) REFERENCE User_T(IdUser)
);


-- what keywords did I missed here?
CREATE TABLE TimeSheetHour(
    IdTimeSheetHour NUMBER(10,0) NOT NULL,
    IdTimeSheet NUMBER(10,0) NOT NULL,
    IdUser  NUMBER(10,0) NOT NULL,
    IdTimeCategory  NUMBER(10,0) NOT NULL,
    IdTask  NUMBER(10,0) NOT NULL,
    Quantity NUMBER(5,0) NOT NULL,
    TimeSheetHour_Description VARCHAR2(200),
    CONSTRAINT IdTimeSheetHour_PK PRIMARY KEY (IdTimeSheetHour),
    CONSTRAINT IdTimeSheet_FK FOREIGN KEY (IdTimeSheet) REFERENCE (TimeSheet),
    CONSTRAINT IdUser_FK FOREIGN KEY (IdUser) REFERENCE (User_T),
    CONSTRAINT IdTimeCategory_FK FOREIGN KEY (IdTimeCategory) REFERENCE (TimeCategory),
    CONSTRAINT IdTask_FK FOREIGN KEY (IdTask) REFERENCE Tasks(IdTask)
);

CodePudding user response:

The keyword is REFERENCES not REFERENCE.

Then you have constraints with duplicate names IdProject_FK.

Then you have foreign key constraints where you do not specify the table being referenced.

I.e.:

CONSTRAINT IdTimeSheet_FK FOREIGN KEY (IdTimeSheet) REFERENCE (TimeSheet)

Should be:

CONSTRAINT IdTimeSheet_FK FOREIGN KEY (IdTimeSheet) REFERENCES TimeSheet(IdTimeSheet)

or, without the braces and the explicit column name:

CONSTRAINT IdTimeSheet_FK FOREIGN KEY (IdTimeSheet) REFERENCES TimeSheet
  • Related