0%

資料庫理論

Database System

設計資料庫的階段(Phases for designing a database)

  • Requirements specification and analysis
  • Conceptual design
  • Logical design
  • Physical design

Database System要素

  • meta-data
    • 描述database的結構
  • database catalog
    • DBMS使用
    • 給需要了解結構的user使用

Program-data independence
資料檔案的結構儲存在DBMS目錄裡和存取程式是隔離的

data abstraction(資料抽象化)

  • Conceptual representation
    • 不包括資料是如何儲存的細節或是操作是如何實作出來的
  • Data model
    • Type of data abstraction used to provide conceptual representation
    • 提供conceptual representation的資料抽象化型態

Sharing of Data and Multiuser Transaction Processing(資料分享與多使用者交易處理)

允許多個使用者在同一時間連線到database

Concurrency control software
確保數個使用者想要更新同一數據時,可以受到控制
ex. 售票員

Database administrators(DBA)

  • 授權存取資料庫
  • 監督資料庫的使用
  • 負責需要的軟硬體資源

Database designers

  • 識別要存取在資料庫的資料
  • 選擇合適的結構來儲存

End users

  • 需要連接到資料庫的人

參考資料

Database Languages and Architectures

Schemas, Instances, and Database State

  • Database schema
    • database的描述
  • Dchema diagram
    • 呈現選取的schema
  • Schema construct
    • 每個在schema的Object
  • Database state
    • Database中特定時間的Data

three-Schema Architecture

  • 外部層(External Level)
    • 描述資料庫的部分資料
    • 負責不同使用者所需要觀看的部分資料,而將資料庫的其他部分隱藏起來
  • 概念層(Conceptual Level)
    • 描述整個資料庫的結構
    • 是以DBA觀點所看到的完整資料庫系統
  • 內部層(Internal Level)
    • 描述架構中的有關資料庫實際的儲存與存取路徑的完整資訊

補充

目的是達到Data independence

:::info
Data Independence
上下層並不會互相影響
:::

而Data independence分為兩種

  • Logical : 外部與概念對應,當Conceptual schema更改時,只要更改兩層之間的映對,而不需要直接更改其他層的Schema
  • Physical : 概念與內部對應,當Internal schema更改時,只要更改Internal schema與conceptual schema的映對,而不需要更改Conceptual schema或External schema

更詳細的說明

DBMS language

  • Data definition language(DDL, 資料定義語言)
    • 定義schemas(Conceptual schema, Internal schema)
  • Storage definition language(SDL, 儲存定義語言)
    • 明確定義internal schema
  • View definition language(VDL, 視野定義語言)
    • 根據Conceptual schema 定義user views/mapping
  • Data manipulation language(DML, 資料操縱語言)
    • 允許retrieval,insertion,deletion,modification
    • High-level DML
      • 高階DML為集合導向的(set-oriented)
    • Low-level DML
      • 低階DML為一次一筆紀錄(record-at-a-time)

DBMS要素

  • Buffer management
  • Stored data manager
  • DDL compiler
  • Interactive query interface
  • Precompiler
  • Runtime database processor
  • System catalog
  • Comcurrency control system
  • Backup and recovery system

必須要有以下功能

  • Loading(載入)
  • Backup(備份)
  • Database storage reorganization(重組檔案)
  • Performance monitoring(效能監控)

兩層式C/S架構

  • Server handles
    • Query and transaction functionality related to SQL processing
  • Client handles
    • 使用者介面或是程式

在兩層之間的介面稱為ODBC,是一種API使用戶端程式可以呼叫DBMS

三層式C/S架構

在Web server常見

會在Client和databese server中間加入intermediate layer,扮演在資料庫伺服器與用戶端之間傳送資料的中間角色

DBMS分類

  • Data model
    • Relational
    • object
    • Hierarchical and network(網路)
    • native XML DBMS
  • User
    • 單一使用者
    • 多使用者
  • Number of sites
    • 集中式
    • 分散式

補充

The basic relational model

Relational Model Concepts

資料庫為多個集合的關聯

名稱對應

理論 實務
Relation Table
Tuple Row
Attribute Column

Domain為無法分割值的集合
(可稱為定義域)

  • relation(relaiton state)
    • n-tuple的集合,可表示成 $r = { t_1, t_2,…,t_m}$
    • 每個n-tuple t
      • 為有n個值的list
      • 每個 $v_i, 1\leq i \leq n$ 是 $dom(A_i)$中的一個元素或是NULL
    • Degree of relation
      • relation schema中attribute的數目
  • Cardinality
    • domain中值的數目

Characteristics of Relations(關聯的特性)

  • Relation 中的 tuple沒有順序
  • tuple中的值
    • 每個tuple的值都是atomic
    • Flat relation model
  • NULL值
    • 表示為unknown或是不能用tuple表示
    • 可能情況
      • 未知值
      • 值存在但不可用
      • 這個attribute不能表示tuple

Relation model 符號

  • Relation schema R of degree n
    • 表示為$R(A_1,A_2,…A_n)$
  • 大寫的 $Q,R,S$
    • 表示relation name
  • 小寫的 $q,r,s$
    • 表示relation state
  • $t,u,v$
    • 表示tuple

Relation model 限制

  • Entity integrity constraint
    • Primary key不可為NULL
  • Key Constraints
    • super key 超鍵
      • 符合唯一性的key
    • Candidate key 候選鍵
      • 符合唯一性以及最小性的key
    • Primary key 主鍵
      • 從Candidate key中選出來
      • 最具識別意義的屬性
      • 不可為空
    • Alternate Key 次要鍵
      • 沒有被選為主鍵的其他Candidate key
    • Foreign Key 外鍵
      • Relation中被用來參考到其他表格Primary key的key,就是Foreign key
      • 必須和Primary key有相同的domain
      • Foreign key 的值必須存在於Primary key的值=>參考完整性 (Referential Integrity)
  • State constraints
    • Define the constraints that a valid state of the database must satisfy
  • Transition constraints
    • Define to deal with state changes in the database

操作種類

  • Insert
    • 可以打破上面四個限制
    • 如果打破了任何一個限制,一般而言會拒絕
  • Delete
    • 只能打破referential integrity
  • Update