alter table GJJY.JY_DIC_CROP
drop constraint FK_ZMLB;
alter table GJJY.JY_DIC_CROP
drop constraint FK_ZWLB;
alter table GJJY.JY_DIC_CROP
add constraint FK_ZMLB foreign key (ZMLB)
references sys_dic (code);
alter table GJJY.JY_DIC_CROP
add constraint FK_ZWLB foreign key (ZWLB)
references sys_dic (code);
drop constraint FK_ZMLB;
alter table GJJY.JY_DIC_CROP
drop constraint FK_ZWLB;
alter table GJJY.JY_DIC_CROP
add constraint FK_ZMLB foreign key (ZMLB)
references sys_dic (code);
alter table GJJY.JY_DIC_CROP
add constraint FK_ZWLB foreign key (ZWLB)
references sys_dic (code);
如获取全部外键:
select * from user_constraints t
where t.table_name = 'JY_DIC_CROP'
and t.r_owner = 'GJJY'
and t.constraint_type ='R'
and t.constraint_name = 'FK_ZMLB';
所有有时间在Oracle需要手动处理数据,在删除一张主表时,要先把引用主表记录的次表记录删除;删除主表记录时,往往会报FK制约引用的错误。
上面会有外键名称。通过上面语句我们就能找到所属从表了,再做处理。