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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

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

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

概念:

主鍵:用戶選擇元組標識的一個候選鍵,主鍵不允許為空

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

超鍵:能唯一的標識元組的屬性集

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

實例:

假如有以下學生和教師兩個表:

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

Teacher(teacher_no,teacher_name,teacher_salary)

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

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

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

外鍵:teacher_no為兩個表的公共關(guān)鍵字,且是Teacher表的主鍵,因此teacher_no是Student表的外鍵,用來描述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总结...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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