sql - 删除表命令在 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的功能吗?除非我更改表的名称,否则它将不起作用,但是在更改名称后,当我第二次尝试运行代码时,它再次给了我上述错误。
解决方案
这是因为您正在删除 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
推荐阅读
- android - dagger2 和 android:在地图上注入视图模型的加载模块
- unix - 获取 IP 地址的主机名
- swift - 如何在 Swift 中每天只显示一次信标通知?
- git - 我在 TFS 团队资源管理器中使用 git 的当前工作项
- python-3.x - 使用 XPath 查找文本字段列表
- unity3d - 尝试以球形实例化多个游戏对象
- android - 提交到 SharedPreferences 变量
- java - 创建新的 Rect 对象或重用旧的,即在性能方面更改现有的参数
- azure - 如何在 Azure 函数中写入 Azure 事件网格主题
- python - python - 单行嵌套 For 循环