暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 约束

askTom 2017-04-12
217

问题描述

如果我的外键指向表的主键,有没有一种方法可以删除表而无需级联?有什么想法吗?

专家解答

如果您 * 不 * 使用casacde,那么您希望子表指向什么?

您必须使用 “cascade” 或明确删除外键约束。“禁用” 是不够的,例如

SQL> create table t1 ( x int primary key ) ;

Table created.

SQL> insert into t1 values (1);

1 row created.

SQL> create table t2 ( y int, constraint fk foreign key ( y ) references t1(x));

Table created.

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


SQL> alter table t2 disable constraint fk;

Table altered.

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

复制


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论