Sql 我无法用外键关系构建数据。截断后,子数据将被截断

Sql 我无法用外键关系构建数据。截断后,子数据将被截断,sql,oracle,oracle11g,sqlplus,Sql,Oracle,Oracle11g,Sqlplus,我有外键关系的表。我已经截断了子表数据,但在此之后,我也无法删除父表数据。为什么?我对那个外键列有主键约束。altertable禁用约束; alter table <Table Name> disable constraint <constraint name>; 禁用约束删除数据并再次添加约束 示例表和数据: SQL> create table tdept (deptno number constraint pkd primary key); Table c

我有外键关系的表。我已经截断了子表数据,但在此之后,我也无法删除父表数据。为什么?我对那个外键列有主键约束。

altertable禁用约束;
alter table <Table Name> disable constraint <constraint name>;
禁用约束删除数据并再次添加约束

示例表和数据:

SQL> create table tdept (deptno number constraint pkd primary key);

Table created.

SQL> create table temp  (emp number primary key, deptno number constraint fkd
  2    references tdept (deptno));

Table created.

SQL>
SQL> insert into tdept values (100);

1 row created.

SQL> insert into temp values (1, 100);

1 row created.

SQL>
这就是您所做的-截断的详细信息(子)表:

截断主(父)表不起作用:

SQL> truncate table tdept;
truncate table tdept
               *
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
因此,禁用外键约束,截断主表并启用FK:

SQL> alter table temp disable constraint fkd;

Table altered.

SQL> truncate table tdept;

Table truncated.

SQL> alter table temp enable constraint fkd;

Table altered.

您得到的是什么错误?SQL错误:ORA-02266:表中由启用的外键02266引用的唯一/主键。00000-“表中由启用的外键引用的唯一/主键”我尝试过,但没有成功。我无法禁用约束,因为它是表的主键。同样,没有错误或表DDL,这很难猜测。错误就像无法禁用索引或表的主约束一样。
请从所有约束中选择约束名称,其中table\u NAME=和constraint\u TYPE='R'
@peridin请禁用上述约束,谢谢。我得到了它。
SQL> alter table temp disable constraint fkd;

Table altered.

SQL> truncate table tdept;

Table truncated.

SQL> alter table temp enable constraint fkd;

Table altered.