首页 > 解决方案 > 删除表命令在 Oracle SQL 开发人员中不起作用,它不会在使用时删除现有表?

问题描述

drop Table countries;
drop Table regionss;

create TABLE regionss(
region_id NUMBER(3),
region_Name VARCHAR2(25),
CONSTRAINT regions_pk PRIMARY KEY(region_id)
);

create TABLE countriess(
country_id CHAR(2),
country_Name VARCHAR2(40),
region_id NUMBER(3),
CONSTRAINT countries_pk PRIMARY KEY(country_id),
CONSTRAINT regions_countries_fk FOREIGN KEY (region_id) REFERENCES regionss (region_id) 
);

我收到这些错误

Error starting at line : 4 in command -
create TABLE regionss(
region_id NUMBER(3),
region_Name VARCHAR2(25),
CONSTRAINT regions_pk PRIMARY KEY(region_id)
)
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Error starting at line : 10 in command -
create TABLE countriess(
country_id CHAR(2),
country_Name VARCHAR2(40),
region_id NUMBER(3),
CONSTRAINT countries_pk PRIMARY KEY(country_id)
)
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

删除给它的现有表不是Drop Command的功能吗?除非我更改表的名称,否则它将不起作用,但是在更改名称后,当我第二次尝试运行代码时,它再次给了我上述错误。

标签: sqloracleoracle-sqldeveloperddl

解决方案


这是因为您正在删除 tablecountries并创建 table countriess。这会导致错误链:

  • 你不能删除不存在的表(countries
  • regionss存在,但它具有coutriess防止它被删除的外键 (from )。

SQL> drop Table countries;
drop Table countries
           *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> drop Table regionss;
drop Table regionss
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys

推荐阅读