日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
DB2創(chuàng)建外鍵時(shí)選項(xiàng)的掌握方案描述

以下的文章主要向大家講述的是快速掌握DB2創(chuàng)建外鍵時(shí)選項(xiàng)的方案,其中包括創(chuàng)建測試表,對On Delete 的選項(xiàng)介紹,以下就是文章的主要內(nèi)容的詳細(xì)描述,望大家在瀏覽之后會對其有更深的了解。

創(chuàng)建外鍵時(shí)的選項(xiàng):

1.創(chuàng)建測試表:

drop table student;

 
 
 
 
  1. drop table class;   
  2. drop table student_class;   
  3. 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 ;   
  4. 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 ;   
  5. Create table student_class(student_class_id integer,student_id integer,class_id integer) in luzl_32k_tb index in luzl_32k_tb;   
  6. alter table student_class add constraint if_class foreign key(class_id) references class(class_id) ON DELETE cascade ON UPDATE RESTRICT;   
  7. alter table student_class add constraint if_student foreign key(student_id) references student(student_id) ON DELETE cascade ON UPDATE RESTRICT;   
  8. Insert into student(student_id,student_name) values(1,'luzl');   
  9. Insert into class(class_id,class_name) values(1,'db2');   
  10. 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)指定的話,如果刪除父記錄,依賴于他的子記錄也會自動刪除.相當(dāng)于級聯(lián)刪除.如果指定no action和cascade都會報(bào)錯(cuò),因?yàn)檫€有子記錄所以無法刪除該記錄.set nul允許刪除父記錄并且l會將子表中與父表關(guān)聯(lián)的字段設(shè)置為null.

3.On Update 只有兩個(gè)選項(xiàng) no action/restrict.它們在更新和刪除時(shí)并沒有區(qū)別:如果與子表關(guān)聯(lián)不允許刪除.

4.另外還需要注意一點(diǎn),父表中的字段必須是主鍵,才能做為子表的外鍵。

上述的相關(guān)內(nèi)容就是對快速掌握DB2創(chuàng)建外鍵時(shí)的選項(xiàng)的描述,希望會給你帶來一些幫助在此方面。

【編輯推薦】

  1. DB2 CMO安裝7.1.2.6補(bǔ)丁之后會出現(xiàn)什么?
  2. IBM DB2中新手要了解的東西有哪些?
  3. DB2 For z/OS or OS/390性能如何正確管理?
  4. IBM DB2 Content Manager V83安裝與SQL0818
  5. 掛起DB2 diag.log中看到了什么?

文章標(biāo)題:DB2創(chuàng)建外鍵時(shí)選項(xiàng)的掌握方案描述
當(dāng)前鏈接:http://www.5511xx.com/article/cccsspo.html