自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

DB2 創(chuàng)建外鍵的N多操作選項(xiàng)如何掌握?

數(shù)據(jù)庫(kù)
以下的文章主要向大家講述的是掌握DB2 創(chuàng)建外鍵時(shí)的操作選項(xiàng)的簡(jiǎn)便方法,以及對(duì)其在實(shí)際操作中要用到的實(shí)際操作代碼的描述。

我們今天主要向大家講述的是教你掌握DB2 創(chuàng)建外鍵時(shí)的操作選項(xiàng)的簡(jiǎn)便方案,以及對(duì)其在實(shí)際操作中要用到的相關(guān)實(shí)際操作代碼的描述,以下就是文章的主要內(nèi)容的詳細(xì)描述,望大家會(huì)對(duì)其有更好的了解。

本文介紹了如何快速掌握DB2 創(chuàng)建外鍵時(shí)的選項(xiàng)

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

  1. drop table student; drop table class; drop table student_class;  

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

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

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

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

4.另外還需要注意一點(diǎn),父表中的字段必須是主鍵,才能做為子表的外鍵。以上的相關(guān)內(nèi)容就是對(duì)教你快速掌握DB2 創(chuàng)建外鍵時(shí)的選項(xiàng)的介紹,望你能有所收獲。

【編輯推薦】

  1. 對(duì)DB2 9.7武器的功能的描述
  2. IBM DB2連接集中器的基本操作原理
  3. DB2 V9.5 新特性有哪些好處?
  4. DB2 batch update注意事項(xiàng)的描述
  5. DB2V8升級(jí)到DB2V95數(shù)據(jù)庫(kù)的方案分析

 

責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2010-08-19 09:44:04

DB2創(chuàng)建外鍵

2010-08-18 09:09:15

DB2創(chuàng)建外鍵

2010-08-20 08:37:59

DB2創(chuàng)建外鍵

2011-03-23 10:25:21

DB2數(shù)據(jù)庫(kù)創(chuàng)建外鍵選項(xiàng)

2010-08-10 13:44:51

DB2創(chuàng)建外鍵

2010-07-29 08:56:53

DB2基本操作指令

2010-08-02 14:34:53

DB2數(shù)據(jù)移動(dòng)

2010-09-01 09:27:21

DB2表名

2010-07-27 09:29:40

DB2數(shù)據(jù)移動(dòng)

2010-08-04 11:12:09

DB2命令執(zhí)行

2010-11-02 14:08:29

DB2創(chuàng)建用戶

2010-09-07 15:39:52

DB2創(chuàng)建跨庫(kù)視圖

2010-07-27 11:08:49

DB2數(shù)據(jù)移動(dòng)

2010-08-16 09:39:03

DB2基礎(chǔ)知識(shí)DB2c

2010-11-02 14:53:38

DB2權(quán)限

2010-11-02 11:36:10

DB2索引創(chuàng)建

2010-09-06 15:27:50

DB2

2010-08-16 09:48:28

DB2數(shù)據(jù)庫(kù)

2010-11-02 14:45:12

DB2創(chuàng)建表空間

2010-07-30 10:32:31

DB2數(shù)據(jù)移動(dòng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)