新聞中心
此文章主要講述的是掌握DB2創(chuàng)建外鍵時(shí)選項(xiàng)的實(shí)際操作描述,你如果對(duì)快速掌握DB2創(chuàng)建外鍵時(shí)選項(xiàng)的實(shí)際操作描述有興趣的話(huà)你就可以點(diǎn)擊以下的文章進(jìn)行觀看了,以下就是相關(guān)內(nèi)容的具體描述。

創(chuàng)新互聯(lián)是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專(zhuān)注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開(kāi)發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計(jì),網(wǎng)站模板,微信公眾號(hào)開(kāi)發(fā),軟件開(kāi)發(fā),成都小程序開(kāi)發(fā),10余年建站對(duì)汽車(chē)玻璃修復(fù)等多個(gè)領(lǐng)域,擁有豐富設(shè)計(jì)經(jīng)驗(yàn)。
創(chuàng)建外鍵時(shí)的選項(xiàng):
1.創(chuàng)建測(cè)試表:
- drop table student;
- drop table class;
- drop table student_class;
- Create table student(student_id integer not null,student_name varchar(200), CONSTRAINT P_KEY_1 primary key (student_id))
in luzl_32k_tb index in luzl_32k_tb ;- Create table class(class_id integer not null,class_name varchar(200), CONSTRAINT P_KEY_2 primary key (class_id)) in luzl_32k_tb index in luzl_32k_tb ;
- Create table student_class(student_class_id integer,student_id integer,class_id integer) in luzl_32k_tb index in luzl_32k_tb;
- alter table student_class add constraint if_class foreign key(class_id) references class(class_id) ON DELETE cascade ON UPDATE RESTRICT;
- alter table student_class add constraint if_student foreign key(student_id) references student(student_id) ON DELETE cascade ON UPDATE RESTRICT;
- Insert into student(student_id,student_name) values(1,'luzl');
- Insert into class(class_id,class_name) values(1,'db2');
- Insert into student_class(student_class_id,student_id,class_id) values(1,1,1);
2.On Delete 的選項(xiàng)有
Restrict/no action/cascade/set null.其中cascade選項(xiàng)指定的話(huà),如果刪除父記錄,依賴(lài)于他的子記錄也會(huì)自動(dòng)刪除.相當(dāng)于級(jí)聯(lián)刪除.如果指定no action和cascade都會(huì)報(bào)錯(cuò),因?yàn)檫€有子記錄所以無(wú)法刪除該記錄.set nul允許刪除父記錄并且l會(huì)將子表中與父表關(guān)聯(lián)的字段設(shè)置為null.
3.On Update 只有兩個(gè)選項(xiàng) no action/restrict.它們?cè)诟潞蛣h除時(shí)并沒(méi)有區(qū)別:如果與子表關(guān)聯(lián)不允許刪除.
4.另外還需要注意一點(diǎn),父表中的字段必須是主鍵,才能做為子表的外鍵。以上的相關(guān)內(nèi)容就是對(duì)快速掌握DB2創(chuàng)建外鍵時(shí)的選項(xiàng)的介紹,望你能有所收獲。
以上的相關(guān)內(nèi)容就是對(duì)快速掌握DB2創(chuàng)建外鍵時(shí)的選項(xiàng)的介紹,望你能有所收獲。
當(dāng)前名稱(chēng):DB2創(chuàng)建外鍵時(shí)選項(xiàng)如何快速掌握?
標(biāo)題網(wǎng)址:http://m.fisionsoft.com.cn/article/dhsijoi.html


咨詢(xún)
建站咨詢(xún)
