欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么理解oracle外鍵約束

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)怎么理解oracle外鍵約束,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

在肅寧等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),成都營(yíng)銷網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè)公司,肅寧網(wǎng)站建設(shè)費(fèi)用合理。

外鍵約束的創(chuàng)建方法
tes1的建表語(yǔ)句為create table test1 (hid number primary key,hname varchar2(10));
1、創(chuàng)建表的同時(shí)創(chuàng)建外鍵約束
1.1、列級(jí)別
create table test2 (hid1 number(10) REFERENCES test1(hid),hname1 varchar2(10));--系統(tǒng)自動(dòng)生成約束名
create table test2 (hid1 number(10) constraint hid_pk REFERENCES test1(hid),hname1 varchar2(10));
1.2、表級(jí)別
create table test2 (hid1 number(10) ,hname1 varchar2(10),foreign key (hid1) REFERENCES test1(hid));--系統(tǒng)自動(dòng)生成約束名
create table test2 (hid1 number(10) ,hname1 varchar2(10),constraint hid_pk foreign key (hid1) REFERENCES test1(hid));

2、表創(chuàng)建后再創(chuàng)建外鍵約束
ALTER TABLE test2 ADD  FOREIGN KEY (hid1)  REFERENCES test1 (hid);--系統(tǒng)自動(dòng)生成約束名
ALTER TABLE test2 ADD CONSTRAINT hid_pk FOREIGN KEY (hid1)  REFERENCES test1 (hid);



子表操作會(huì)遇到的報(bào)錯(cuò)
不能修改值為父表不存在的記錄
不能插入父表不存在的記錄
create table test1 (hid number primary key,hname varchar2(10));
create table test2 (hid1 number(10) constraint hid_pk REFERENCES test1(hid),hname1 varchar2(10));
insert into test1 values(1,'1');
insert into test2 values(1,'100');
update test2 set hid1=2 where hid1=1;--報(bào)錯(cuò)ORA-02291: 違反完整約束條件 (HR.HID_PK) - 未找到父項(xiàng)關(guān)鍵字
insert into test2 values(2,'100');--報(bào)錯(cuò)ORA-02291: 違反完整約束條件 (HR.HID_PK) - 未找到父項(xiàng)關(guān)鍵字
drop table test2;
drop table test1;


父表操作遇到的報(bào)錯(cuò)
create table test1 (hid number primary key,hname varchar2(10));
create table test2 (hid1 number(10) constraint hid_pk REFERENCES test1(hid),hname1 varchar2(10));
insert into test1 values(1,'1');
insert into test2 values(1,'100');
delete from test1;--報(bào)錯(cuò)ORA-02292: 違反完整約束條件 (HR.HID_PK) - 已找到子記錄
truncate table test1;--報(bào)錯(cuò)ORA-02266: 表中的唯一/主鍵被啟用的外鍵引用
drop table test1;--報(bào)錯(cuò)ORA-02449: 表中的唯一/主鍵被外鍵引用
update test1 set hid=2 where hid=1;--報(bào)錯(cuò)ORA-02292: 違反完整約束條件 (HR.HID_PK) - 已找到子記錄

create table test1 (hid number primary key,hname varchar2(10));
create table test2 (hid1 number(10) constraint hid_pk REFERENCES test1(hid),hname1 varchar2(10));
insert into test1 values(1,'1');
truncate table test1;
drop table test1;--報(bào)錯(cuò)ORA-02266: 表中的唯一/主鍵被啟用的外鍵引用

create table test1 (hid number primary key,hname varchar2(10));
create table test2 (hid1 number(10) constraint hid_pk REFERENCES test1(hid),hname1 varchar2(10));
drop table test1;--報(bào)錯(cuò)ORA-02266: 表中的唯一/主鍵被啟用的外鍵引用


delete報(bào)錯(cuò)的解決方法
解決方法1
delete from test2;
delete from test1;

解決方法2(不保留子表記錄)
alter table test2 drop constraint hid_pk;
ALTER TABLE test2 ADD CONSTRAINT hid_pk FOREIGN KEY (hid1)  REFERENCES test1 (hid) ON DELETE CASCADE;
delete from test1;

解決方法3(保留子表記錄,但是字表對(duì)應(yīng)字段值變成null,如下test2的hid1為null了)
alter table test2 drop constraint hid_pk;
ALTER TABLE test2 ADD CONSTRAINT hid_pk FOREIGN KEY (hid1)  REFERENCES test1 (hid) ON DELETE SET NULL;
delete from test1;


truncate報(bào)錯(cuò)的解決方法
drop table test2;
truncate table test1;

alter table test1 disable primary key cascade;
truncate table test1;

alter table test1 disable primary key cascade;
truncate table test2;
truncate table test1;

采用如下一樣會(huì)報(bào)錯(cuò)
truncate table test2;
truncate table test1;--繼續(xù)報(bào)錯(cuò)ORA-02266: 表中的唯一/主鍵被啟用的外鍵引用


drop報(bào)錯(cuò)的解決方法
drop table test1 cascade constraints;

drop table test2;
drop table test1;

采用如下一樣會(huì)報(bào)錯(cuò)
alter table test1 disable primary key cascade;
truncate table test2;
drop table test1;

上述就是小編為大家分享的怎么理解oracle外鍵約束了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前文章:怎么理解oracle外鍵約束
當(dāng)前地址:http://aaarwkj.com/article32/pjdhsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、軟件開發(fā)Google、面包屑導(dǎo)航服務(wù)器托管、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
亚洲国产欧美日韩久久| 欧美香蕉一区二区视频| 高清av在线国产成人精品自拍| 熟女乱熟乱熟妇综合网二区| 亚洲欧美国产成人在线| 精品人妻中文字幕在线| 国内丰满少妇嗷嗷叫在线播放| 国产三级黄在线观看| 一区二区三区在线观看精品| 亚洲亚洲精品av在线动| 日韩在线中文字幕一区| 国产亚洲一区二区日韩欧美| 手机蜜臀av在线播放| avav男人天堂亚洲天堂| 亚洲国产精品久久久久国产精品| 亚洲香蕉av一区二区蜜桃| 国产精品久久久久久爽| 中文字幕日韩不卡顿一区二区| 日本色小姐美国青青草原| 久久久久亚洲av成人网人| 免费看欧美黄片在线看| 亚洲精品一区av在线观看| 成人粉嫩av一区二区白浆| 91在线视频麻豆国产| 国产免费高清av在线| 精品久久一区麻豆香蕉| 日本黄色美女日本黄色| 国产乱av一区二区三区| 麻豆精东传媒一区二区| 国产熟女高潮一区二区| 五月天丁香婷婷一区二区| av天堂久久这里只有精品美国| 中文字幕久久亚洲一区| 日本中文字幕一二三四区| 国产精品久久午夜伦鲁鲁| 日本在线人妻中文字幕| 夜夜春久久天堂亚洲精品| 国产一边打电话一边操| 91福利免费在线看| av男人的天堂一区二区| 免费在线免费观看av|