M
M
marsel812018-10-22 13:27:57
Oracle
marsel81, 2018-10-22 13:27:57

Why is Create table not compatible with alter?

CREATE TABLE EMPLOYEES (
    EMPLOYEE_ID NUMBER,
    FIRSTNAME VARCHAR(20),
    LASTNAME VARCHAR(20),
    PATRONYMIC VARCHAR(20),
    BIRTHDATE DATE,
    MOBILENUM NUMBER(8) NOT NULL UNIQUE,
    HOMENUM NUMBER(8) NOT NULL UNIQUE,
    CONSTRAINT FIO_BITH UNIQUE(FIRSTNAME,LASTNAME,PATRONYMIC,BIRTHDATE) 
);

ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMPLOYEES_PK PRIMARY KEY(EMPLOYEE_ID);

ALTER TABLE EMPLOYEES
    ADD CONSTRAINT FK_OBJECT
    FOREIGN KEY(OBJECT_ID)
    REFERENCES OBJECTS(OBJECT_ID);

CREATE TABLE OBJECTS (
    OBJECT_ID NUMBER,
    OBJECT_NAME VARCHAR(20),
    OBJECT_SQUARE NUMBER(4),
    OBJECT_COST NUMBER(6),
    CONSTRAINT CHECK_COST_SQUARE
        CHECK (OBJECT_COST > 0 AND OBJECT_SQUARE > 0)
);

ALTER TABLE OBJECTS
    ADD CONSTRAINT OBECTS_PK PRIMARY KEY(OBJECT_ID);

Throws an error when adding a foreign key that it does not see the objects table

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Radjah, 2018-10-22
@Radjah

Doesn't it bother you that at the moment the second ALTER is called, the "OBJECTS" table is not yet in the database?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question