oracle新增外來鍵約束

2021-07-02 04:18:54 字數 715 閱讀 1363

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);  

如獲取全部外來鍵:

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制約引用的錯誤。

上面會有外來鍵名稱。通過上面語句我們就能找到所屬從表了,再做處理。

Oracle表中新增外來鍵約束

新增主鍵約束 alter table ga airline add constraint pk airline id primary key airline id 有三種形式的外來鍵約束 1 普通外來鍵約束 如果存在子表引用父表主鍵,則無法刪除父表記錄 2 級聯外來鍵約束 可刪除存在引用的父表記錄,...

oracle新增外來鍵約束的方法

給表新增外來鍵約束分兩種情況,一種是剛建表的時候直接新增外來鍵約束,另一種則是表已經建立好了再新增外來鍵約束。建表時新增外來鍵約束 create table test a id number not null primary key,name varchar2 50 create table tes...

oracle外來鍵約束

新建父表 sql create table teacher 2 3 id number primary key,4 name varchar2 10 5 table created.新建子表 sql 1 create table student 2 3 id number primary key,4...