Database 在sqlplus中创建表时出错

Database 在sqlplus中创建表时出错,database,oracle,sqlplus,Database,Oracle,Sqlplus,我是sqlplus新手,曾尝试运行一个sql脚本来创建一些表,但一旦我尝试运行它,它就会给我一个错误,告诉我表或视图不存在,我不知道如何修复此错误。 我的剧本是: drop table Borrower; create table Borrower ( bid char(100) not null, password char(100) not null, name char(100) null, address char(100) null,

我是sqlplus新手,曾尝试运行一个sql脚本来创建一些表,但一旦我尝试运行它,它就会给我一个错误,告诉我表或视图不存在,我不知道如何修复此错误。 我的剧本是:

 drop table Borrower;
 create table Borrower (
     bid char(100) not null, 
     password char(100) not null, 
     name char(100) null, 
     address char(100) null, 
     phone char(100) null, 
     emailAddress char(100) null, 
     sinOrStNo char(100) null, 
     expiryDate date null, 
     --type ENUM('student','faculty','staff'),
     type char(100) not null,
     --CONSTRAINT Btype_check CHECK (type IN ('student','faculty','staff')),
     FOREIGN KEY (type) references BorrowerType(type),
     PRIMARY KEY (bid));
 grant select on Borrower to public;

删除或创建表的顺序很重要,因为如果外键引用另一个表,则在删除自己的表之前不能删除该表。 在本例中,必须先删除借贷者表,再删除借贷者类型表

“外键引用的表中的唯一/主键”

数据完整性对于数据库的正常运行至关重要,因此,如果一个表的主键被另一个表的外键引用,Oracle不会让我们删除该表。所以它抛出了ORA-02449

因此,考虑到这种设置:

create table t_parent (
    id number not null
    , constraint tp_pk primary key (id)
);
create table t_child (
    id number not null
    , p_id number not null 
    , constraint tc_pk primary key (id)
    , constraint tc_tp_fk foreign key (p_id)
        references t_parent (id)
);
有三种方法可以删除表
t\u parent

  • 首先运行
    drop table t_child
    :无子表,无外键
  • 删除阻止外键:
    alter table t_child drop constraint tc_pc_fk
  • 在前一个版本的基础上,让数据库找出外键:
    删除表t\u父级级联约束

  • 第一个选项是最合适的,因为它使数据库处于有效状态(没有表,不存在数据完整性损坏的可能性)。第三种方法的有效用途是从模式中删除所有表的脚本:从数据字典生成这样的脚本很容易

    可能是
    drop table forrower
    命令-您正在尝试删除一个不存在的表,我没有尝试过。它仍然无法创建数据库。数据库还是表?如果只运行
    create
    命令,会发生什么情况?指定的错误表是什么?如果引用的表<代码>借用类型不存在???可以尝试逐个执行命令。首先运行drop table命令,然后运行CREATETABLE命令,然后再运行grant命令。传递准确的错误点和消息