删除没有名称Oracle的外键

Rag*_*hav 3 oracle constraints alter

我想在这里问一个非常基本的问题.在创建表时或创建表后,我们可能/可能不会命名约束.假设我选择不命名外键约束.

该表没有记录.

我可以在不命名的情况下删除外键名称.

我知道如何获取外键的名称,然后使用它删除

alter table my_table drop constraint fk_name;
Run Code Online (Sandbox Code Playgroud)

但我想删除/删除外键约束而不提及其名称.

无论如何要做到这一点?

a_h*_*ame 9

但我想删除/删除外键约束而不提及其名称.

那是不可能的.删除外键约束需要一个名称.但是,您可以找到系统生成的名称:

select constraint_name
from user_constraints
where table_name = 'MY_TABLE'
  and constraint_type = 'R';
Run Code Online (Sandbox Code Playgroud)

将显示表中定义的所有外键MY_TABLE.使用该语句,您甚至可以生成必要的DDL语句:

select 'alter table "'||table_name||'" drop constraint "'||constraint_name||'";'
from user_constraints
where table_name = 'MY_TABLE'
  and constraint_type = 'R';
Run Code Online (Sandbox Code Playgroud)

将该选择的输出保存到文件中,并且您具有从该表中删除所有外键的语句.