傳統程式語言可以做,
但是會有處理上的困難。
與之相對的還有Document Model
把定義記在data dictionary(資料字典)中
Pure 學術理論,以提升資料庫的功能
Attribute:物件的特性或處理的資料
屬於Atomic(不可被分割) 單純的文數字資料
1.multivalued 每個value是一個集合
{ {09XX-XX,04-XXXX} } 裡面是集合(同類型)
2.composite 每個value是不同類型資料的集合
{ (04,XXXXXX) } 裡面是不同類型
Relation schema and instance
A1,A2,…,An are attribute
R = (A) is a relation schema
Instructor = (id,name,phone)
Schema is title or the first row
K是R的部分"集合"
K ⊆ R
Key 用於指出特定唯一的資料列
比如用id去指向特定資料(super key)
Primary key
在Superkey中的極小為candidatekey
Candidate key is minimal(極小)
當屬性有其一缺一不可的情況就是minimal
Foreign key (外部鍵)
Referencing relation → instructor
Referenced relation → department
從Instructor中的資料
透過Foreign key指定到department
Advisor
Primary key限制數量的對應關係
一個老師 → 可以有很多學生
一個學生 → 只能有一個指導老師
Relational Query Language
Pure language:Relational algebra…
Relational algebra:屬於Procedural
1.operator
2.優先度
Six basic operators
Two additional operatiors
Select operation
σ_p®
p: selection predicate(限制式)
and ∧or∨not﹁
Project operation
Π_{A_1,A_2…A_n}
把單或多個欄位選出來
Cartesian product ×
合併表格
重複 → 增加行數 分別寫上來源
或是透過Select與限制式 挑出合理資料列
↓σ_p® 與 × 合成為join operation
Join operation
r✉_Θs
IS NOT NULL
IS NULL
要加distinct才能抓到唯一的老師
抓全部
依xx分群
輸出每群的資料
in each department
挑群
SELECT *
FROM student
ORDER BY 'score' DESC
SELECT *
FROM student
WHERE score > 90 and major = 'english'
建立connect物件 -> 建立stmt物件(配置空間) -> 透過stmt的方法操作資料
先經過預處理分配空間,提升效率(SQL Injection)與安全性。