表不存在,但我显然要在alter语句之前创建一个表

时间:2018-10-09 01:06:34

标签: mysql

我不确定在上一条语句中创建表之后立即尝试更改表时,为什么会显示“表或视图不存在错误”。我在问题中加入了其中一项陈述,但在另外2条中发生了。

CREATE TABLE book_copy (
    branch_code         NUMERIC(2) NOT NULL,
    bc_id               NUMERIC(6) NOT NULL,
    bc_purchase_price   NUMERIC(7,2) NOT NULL,
    bc_reserve_flag     CHAR(1) NOT NULL,
    book_call_no        VARCHAR(20) NOT NULL
);

COMMENT ON COLUMN book_copy.branch_code IS
    'The code of the branch the book refers to';

COMMENT ON COLUMN book_copy.bc_id IS
    'The book crossing ID';

COMMENT ON COLUMN book_copy.bc_purchase_price IS
    'The price of the book';

COMMENT ON COLUMN book_copy.bc_reserve_flag IS
    'Whether or not the book was reserved';

COMMENT ON COLUMN book_copy.book_call_no IS
    'The call number of the book copy';

ALTER TABLE book_copy ADD CONSTRAINT book_copy_pk PRIMARY KEY ( branch_code,
                                                                bc_id );

ALTER TABLE book_copy
    ADD CONSTRAINT book_branch_code_fk FOREIGN KEY ( branch_code )
        REFERENCES branch.branch_code;

ALTER TABLE book_copy
    ADD CONSTRAINT book_call_no_fk FOREIGN KEY ( book_call_no )
        REFERENCES book_detail.book_call_no;






**The Error**
Error starting at line : 39 in command -
ALTER TABLE book_copy
    ADD CONSTRAINT book_branch_code_fk FOREIGN KEY ( branch_code )
        REFERENCES branch.branch_code
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 43 in command -
ALTER TABLE book_copy
    ADD CONSTRAINT book_call_no_fk FOREIGN KEY ( book_call_no )
        REFERENCES book_detail.book_call_no
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

0 个答案:

没有答案