Skip to content
Rain Hu's Workspace
Go back

[IT] 關聯模式的五大鍵 Super key、Candidate Key、Primary Key、Alternate Key、Foreign Key

Rain Hu

關聯模式的條件

  1. 定義域限制: 指資料庫的關聯中的每個屬性質,必須符合該屬性的定義,例如產品名稱必須是字串,薪水必須是整數數字等。
  2. 關聯鍵限制: 指資料庫的關聯中必須有關聯鍵的定義,也就是Super key、Candidate Key、Primary Key、Alternate Key、Foreign Key。這些定義我們稍後再來解釋。
  3. 實體完整限制: 如果關聯存在主鍵(Primary Key),則不能為空。因為如果為空值,無法得知其相關的屬性值到底是描述哪一個實體。
  4. 參考完整限制: 如果關聯存在外鍵(Foreign Key)為非空值,必須有可以參考的主鍵(Primary Key)。因為如果外鍵存在,而無法關連到其他表格的主鍵,這個關聯存在就沒有意義。
  5. 語意完整限制: 這個限制不是必須的,但是可以更完備的描述實體世界的資料。例如交易金額高於100元才可以使用信用卡付款等。

關聯模式的五大鍵


例如學生資料表(student_id, student_no, student_name, student_depid)

student_idstudent_nostudent_namestudent_depid
A12345432100001Rain HuMSE
A12312312300002Mike HuIM
A22123213400003Eva HsuECE
A22312412500004Dudu LiuECE
A12412451200005Gober WeiIT

資料來源:https://www.mysql.tw/2015/04/super-keycandidate-keyprimary.html


Share this post on:

Previous
[CS] Sample cost for performance test
Next
[Algo] 3-2. Binary Search