删除没有名称Oracle的外键

前端之家收集整理的这篇文章主要介绍了删除没有名称Oracle的外键前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在这里问一个非常基本的问题.
在创建表时或创建表后,我们可能/可能不会命名约束.
假设我选择不命名外键约束.

该表没有记录.

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

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

alter table my_table drop constraint fk_name;

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

无论如何要做到这一点?

解决方法

but i want to delete/drop the foreign key constraint without mentioning its name.

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

select constraint_name
from user_constraints
where table_name = 'MY_TABLE'
  and constraint_type = 'R';

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

select 'alter table "'||table_name||'" drop constraint "'||constraint_name||'";'
from user_constraints
where table_name = 'MY_TABLE'
  and constraint_type = 'R';

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

猜你在找的Oracle相关文章