日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

Oracle数据库-主键(primary key)、外键(foreign key)、候选键(candidate key)、超键(super key)和references总结...

發(fā)布時(shí)間:2023/12/4 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle数据库-主键(primary key)、外键(foreign key)、候选键(candidate key)、超键(super key)和references总结... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

主要介紹一下個(gè)人對(duì)主鍵(primary key)、外鍵(foreign key)、候選鍵(Candidate key)、超鍵(super key)、references的總結(jié)

概念:

主鍵:用戶(hù)選擇元組標(biāo)識(shí)的一個(gè)候選鍵,主鍵不允許為空

外鍵:來(lái)描述兩個(gè)表的關(guān)系,外鍵可為空

超鍵:能唯一的標(biāo)識(shí)元組的屬性集

候選鍵:不含有多余屬性的超鍵

實(shí)例:

假如有以下學(xué)生和教師兩個(gè)表:

Student(student_no,student_name,student_age,student_sex,student_credit,teacher_no)

Teacher(teacher_no,teacher_name,teacher_salary)

超鍵:Student表中可根據(jù)學(xué)生編號(hào)(student_no),或身份證號(hào)(student_credit),或(學(xué)生編號(hào),姓名)(student_no,student_name),或(學(xué)生編號(hào),身份證號(hào))(student_no,student_credit)等來(lái)唯一確定是哪一個(gè)學(xué)生,因此這些組合都可以作為此表的超鍵

候選鍵:候選鍵屬于超鍵,且是最小的超鍵,即如果去掉超鍵組合中任意一個(gè)屬性就不再是超鍵了。Student表中候選鍵為學(xué)生編號(hào)(student_no),身份證號(hào)(student_credit)

主鍵:主鍵是候選鍵中的一個(gè),可人為決定,通常會(huì)選擇編號(hào)來(lái)作為表的主鍵。現(xiàn)分別選取student_no,teacher_no作為Student表,Teacher表的主鍵

外鍵:teacher_no為兩個(gè)表的公共關(guān)鍵字,且是Teacher表的主鍵,因此teacher_no是Student表的外鍵,用來(lái)描述Student表和Teacher表的關(guān)系

?

--References用法

創(chuàng)建一張Student表:

Create table Student(

student_no number(10) not null,

student_name varchar2(10) not null,

student_age number(4) not null,

student_sex varchar2(4) not null,

student_credit? varchar2(18) not null,

teacher_no number(10) not null,

constraint PK_Student primary key(student_no)????? --設(shè)置主鍵

);

?

創(chuàng)建一張Teacher表:

Create table Teacher(

teacher_no number(10) not null,

teacher_name varchar2(10) not null,

teacher_salary number(10) not null,

constraint PK_Teacher primary key(teacher_no)?????? --設(shè)置主鍵

);

--創(chuàng)建外鍵約束

alter table Student add constraint FK_Student_References_Teacher (teacher_no) references Teacher(teacher_no);

?

轉(zhuǎn)載于:https://www.cnblogs.com/yangyang17/p/6039022.html

總結(jié)

以上是生活随笔為你收集整理的Oracle数据库-主键(primary key)、外键(foreign key)、候选键(candidate key)、超键(super key)和references总结...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。