Vis*_*hal 2 sql oracle constraints foreign-keys
如果我在创建过程中没有命名外键,如何删除它
create table abc(
id number(10),
foreign key (id) references tab(roll)
);
Run Code Online (Sandbox Code Playgroud)
甚至
alter table abc drop foreign key mn_ibfk_1;
Run Code Online (Sandbox Code Playgroud)
不适合我。我使用的是Oracle 10g。
小智 6
由于您没有指定约束名称,Oracle 会为您生成一个约束名称(类似于SYS_034849548)。
您需要找到约束名称才能删除它:
select constraint_name
from user_constraints
where table_name = 'ABC'
and constraint_type = 'R'
Run Code Online (Sandbox Code Playgroud)
将显示约束名称。然后您可以使用以下方法删除约束:
alter table abc drop constraint <constraint_name>;
Run Code Online (Sandbox Code Playgroud)
(替换<constraint_name>为您使用 SQL 语句检索到的名称)
请注意,语法是. 没有。alter table ... drop constraintdrop foreign key