1 / 37

資料庫系統 Database Systems

資料庫系統 Database Systems. Database System Concepts Schemas diagram. 學生資料. Ex:UNIVERSITY. 課程資料. 每學期課程. 修課成績. 先修課程. Schemas diagram (ex1). create table. Schemas diagram (ex2). 省略資料型態 Student (Name, StudentNumber ,class,Major) 帶有資料型態的表示形式 Student (Name(char 20),

bryson
Download Presentation

資料庫系統 Database Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 資料庫系統Database Systems Database System Concepts Schemas diagram 資料庫系統

  2. 學生資料 Ex:UNIVERSITY 課程資料 每學期課程 修課成績 先修課程 資料庫系統

  3. Schemas diagram (ex1) 資料庫系統

  4. create table Schemas diagram (ex2) • 省略資料型態 • Student (Name, StudentNumber,class,Major) • 帶有資料型態的表示形式 • Student (Name(char 20), StudentNumber(int), class(smallint),Major (char 10) ) • 你也可以這樣表示… • student • ( StudentNumber int not null, • name char(20), class smallint, • Major char(10) • primary key (StudentNumber) ) 加上“create table” 即為建立student表 格的SQL語法 資料庫系統

  5. 資料庫系統Database Systems Relational Database Constraints 若資料異動違反限制條件時… 資料庫系統

  6. Update Operations on Relations • Insert Operation • Delete Operation • Update Operation 資料庫系統

  7. Insert • 定義域限制:假設SALARY為整數型態,在EMPLOYEE中新增一個SALARY為’NT30000’的記錄… • 鍵值限制:在EMPLOYEE中新增一個SSN為123456789的記錄… • 實體完整性限制:在EMPLOYEE中新增一個SSN為NULL的記錄… • 參考完整性限制:假設DNO屬性參考到另一個DEPARTMENT的DNUM主鍵屬性,其中存在1,4,5號等三個部門,如今在EMPLOYEE中新增一個DNO為7的記錄… 資料庫系統

  8. Insert • 違反限制時 • 拒絕Insert • 嘗試更正 資料庫系統

  9. Delete • 只可能違反參考完整性限制 可以刪除! 資料庫系統

  10. Delete • 只可能違反參考完整性限制 不 能 刪 除 資料庫系統

  11. Delete • 違反限制時 • 拒絕Delete • 嘗試更正 • 虛值(null)化 • 連鎖反應(cascade) 資料庫系統

  12. Update • EMPLOYEE的SALARY,DNO可以被更改 • 若將EMPLOYEE的SSN更改可能違反限制 • SSN=‘999887777’更改為‘987654321’ => 違反 “主鍵” 、“參考完整性” 限制 資料庫系統

  13. Update • 違反限制時 • 拒絕UPDATE • 嘗試更正 • 虛值(null)化 • 連鎖反應(系統可能不提供) 資料庫系統

  14. 資料庫系統Database Systems The Relational Algebra (補充) 資料庫系統

  15. The Relational Algebra • 資料模型(Data Model)包括… • 結構 • 限制 • 運算集合(操作) • Relational Data Model 的運算集合稱為Relational Algebra(關聯式代數) 資料庫系統

  16. SELECT soperations • 選擇關聯中滿足選擇條件(Selection condition) 的值組集合 • Ex: 在EMPLOYEE中找出在4號部門工作的tuple • s<selection condition> (relation name) 資料庫系統

  17. SELECT soperations • Ex: 在EMPLOYEE中找出在4號部門工作的tuple • sDNO=4(EMPLOYEE) • sSALARY>30000(EMPLOYEE) 資料庫系統

  18. PROJECT Poperations • 選擇所要的(Attribute list) 的欄位項目 • Ex: 列出EMPLOYEE中的SEX,SALARY • P <attribute list> (relation name) 資料庫系統

  19. PROJECT Poperations P <LNAME,FNAME,SALARY> (EMPLOYEE) P <SEX,SALARY> (EMPLOYEE) 資料庫系統

  20. SELECT sand PROJECT Poperations • Ex1: • 找出SALARY<50000的值組,列出其SEX、SALARY資料 資料庫系統

  21. CARTESIAN PRODUCT EMP_DEPENDENTS ← EMPNAMS DEPENDENT 資料庫系統

  22. CARTESIAN PRODUCT P2_2 EMP_DEPENDENTS ← EMPNAMS DEPENDENT 資料庫系統

  23. Join 運算 • Join 運算含有三個參數 • Join condition (Predicate) : P • 關聯表 R1 • 關聯表 R2 • 將 R1 與 R2 依Join 條件P做 R1∞PR2 ∞ 資料庫系統

  24. Join 運算的範例 等位合併 (Equi-join) ∞ 資料庫系統

  25. NATURAL JOIN • 在執行EQUIJOIN運算後,結果中一定會有兩欄的資料完全相同 • 去除其中一欄仍不影響整體意義,我們稱為「自然合併」 ∞ 資料庫系統

  26. 資料庫系統Database Systems Functional Dependencies and Normalization 更新異常 資料庫系統

  27. 重要觀念 • 良好的語意 • 減少tuple的重複值 • 減少tuple的空值 • 關聯不會出現插入、刪除及修改異常(補充) • 不允許假值組(Spurious Tuples)的存在 資料庫系統

  28. tuple的重複值問題 資料庫系統

  29. tuple的重複值問題 Natural Join Natural-join : EQUIJOIN運算後,去除 Join attributes其中一欄 資料庫系統

  30. 減少tuple的空值 • 空值易導致空間的浪費 資料庫系統

  31. Update anomalies 更新異常(補充) • 資料的插入、刪除、修改產生的異常 • Insertion Anomalies • Deletion Anomalies • Modification Anomalies 資料庫系統

  32. Insertion Anomalies • Case 1: • 新增一筆員工資料,所屬5部門,必須確定部門的相關資訊是對的 • Case 2: • 若有一新成立的部門,但目前沒有任何員工,則此部門資料無法建立(因為SSN為Primary Key) Relation 分割之後可以有效解決Insertion Anomalies的問題 資料庫系統

  33. Relation 分割之後可以有效解決Insertion Anomalies的問題 Natural Join Information 7 987987987 資料庫系統

  34. Deletion Anomalies • 若Zelaya為Administration部門的唯一員工,當Zelaya刪除時,會導致該部門的資訊完全消失 Relation 分割之後可以有效解決 Deletion Anomalies的問題 資料庫系統

  35. Modification Anomalies • 當某一部門的一屬性值被更改時,必須欄帶修正所有的相同屬性值,以確保資料的正確 資料庫系統

  36. Modification Anomalies 資料庫系統

  37. 重要觀念 • 良好的語意 • 減少tuple的重複值 • 減少tuple的空值 • 關聯不會出現插入、刪除及修改異常(補充) • 不允許假值組(Spurious Tuples)的存在 資料庫系統

More Related