我想在这里问一个非常基本的问题.
在创建表时或创建表后,我们可能/可能不会命名约束.
假设我选择不命名外键约束.
在创建表时或创建表后,我们可能/可能不会命名约束.
假设我选择不命名外键约束.
该表没有记录.
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';