Chapter 2 ER Data Model 1 Basic Concept
Chapter 2 E-R Data Model 資料庫系統 1
Basic Concept ER data model將真實世界視為由實體(entity) 與實體間的關係(relationship)所組成 ER data model包含三種類別的符號 Entity sets Relationship sets Attribute 資料庫系統 2
An Example of Entity and Attribute Customer這個entity sets表示銀行所屬顧客的 資料 Customer的attribute包含customer-id, customer-name,customer-birthmonth, customer-money 某個顧客的attribute value為D 12345,John, 5,1200 customer-birthmonth的domain為 1~12的整數, customer-money的domain為正數浮點數 資料庫系統 5
The Characteristic of Attribute(1) Simple vs. Composite Simple是此attribute無法再分割為其他attribute,如 存款金額 Composite是此attribute可分割為其他attribute,如 name可分割為first-name與last-name Single-valued vs. Multivalued Single-valued只有單一值的屬性,如name Multivalued有複數個值的屬性,如phone 資料庫系統 6
The Characteristic of Attribute(2) Derived是由其他attribute所衍生出來的,如 age是由birthyear所衍生 資料庫系統 7
Relationship Sets • Relationship表示實體之間的邏輯關係 123 -45 -4643 Mike L-1 100 487 -42 -1259 John L-2 500 953 -46 -7598 Tom L-3 850 521 -97 -2394 Smith L-4 250 684 -08 -0908 Louis L-5 1000 970 -01 -1505 Bob Customer Loan 資料庫系統 8
Constraints of Relationships(2) 參與限制 Total :在A中每個entity都至少有一個relationship 存在 Partial :在A中只有部分entity有relationship存在 資料庫系統 11
Key 在同一個entity sets中沒有任兩個entity的所有 attribute value是完全一樣的 Key是一組attribute,可用於區分不同的entity Superkey:由一個或多個attribute組成,如 {customer-id}或{customer-id, customer-name} Candidate key :沒有任何子集合是superkey的 superkey,如{customer-id}或{customer-name, customer-address} Primary key :被選作識別entity的candidate key 資料庫系統 13
Weak entity set Entity沒有足夠的attribute來組成一個PK,需 和其他entity產生關聯才有意義 例如 課程資料course這個entity有attribute: courseid 、 coursename 開課紀錄courseoffering這個entity有attribute: offeringid、semester、section courseoffering單獨存在是沒有意義的,所以它是 weak entity set 資料庫系統 15
實作-DB System Management Bank System-customer Create table (entity set) Create field and set type (attribute) Primary key 資料庫系統 16
CREATE TABLE bank(Bank. ID char(20), Bank. Name char(50), Post int, Address char(50), Primary key(Bank. ID)); 資料庫系統 17
E-R diagram(1) 基本符號 長方形:entity sets 雙長方形:weak entity sets 菱形:relationship sets 雙直線:total participation 橢圓:attribute,如是PK則加上underline 雙橢圓:multivalued attribute 虛線橢圓: derived attribute 資料庫系統 18
E-R diagram(2) 直線:連接attribute、entity sets、relationship sets 使用 與 表示entity sets與relationship sets的one to one、one to many、many to one、many to many的關係 資料庫系統 19
三元關係 name 合成屬性 First name Last name id address Branch birthday loan-id One to many Customer Borrower loan amount address age 資料庫系統 20
Last name First name id birthday Customer loan-id 0. . * Borrower 1. . 1 loan amount address age 資料庫系統 22
Schema Diagram customer borrower loan id customer-id loan-id firstname loan-id amount lastname birthday address 資料庫系統 23
Homework(2) 請以選課系統為例子,劃出它的ER diagram 與Schema Diagram,diagram的entity sets至 少需包含course,student,teacher 資料庫系統 25
- Slides: 26