본문 바로가기

DB

[DB][데이터베이스] 2. E-R / Entity와 Relationship

반응형
  • E-R Diagram
  • Attributes
  • Mapping Cardinalities in Relationships
  • Weak Entity Sets
  • Extended E-R Feature

  • UML and Other E-R Notations
  • Reduction to Relation Schemas
  • Design Issues
 by Prof. Chang Hwan Lee

--------------------------------------------------------------------------

1. E-R Diagram

[Fig 1] Entity, Relationship, Attributes (, key)

 

- 데이터베이스 Design ToolE-R 모델은, Logical SchemaTable(relational model)로 자동 변환된다

 

- Entity는 다른 객체와 구별되는 객체고, 이들의 집합은 Entity set이다

- RelationshipEntity 사이의 관계고, 이들의 수학적 관계 집합은 Relationship set이다

  - {(e1, e2, … en) | e1 E1, e2 E2, , en En}

  - binary가 대부분이지만, ternary 이상의 Relationship도 있다. ex) 학생 - 강사 - 프로젝트

  - Entity set의 각각은 Relationship에서 “Role”를 가진다 (1개일 필요 없다)

 

[Fig 2] Relationship Sets with an attribute
[Fig 3] Binary Relationship Sets with an attribute (Diagram)

 


Attributes

- Attributes types

  - Simple/Composite attributes: Component attributes의 여부

  - Single-valued/Multivalued attributes

  - Derived attributes: 다른 attributes로 계산되는 attributes

 

- Domain: attribute에 허용된 값들의 집합

 


Mapping Cardinalities in Relationships

- Binary Relationship일 때 다음 types 중 하나를 따른다

  - One to one

  - One to many

  - Many to one

  - Many to many

 

- Participation

[Fig 4] Total/Partial Participation

 

  - Total participation: 모든 Entity가 Relation에 속한다. (minimum Cardinality는 1이다)

  - Partial participation: entity 관련 X (minimum Cardinality가 0이다)

 

- Cardinality

[Fig 5] Notation of cardinality

 

  - Ternary Relationship에서는 혼란을 피하기 위해 이상의 화살표를 피하도록 한다

 

[Fig 6] arrow out Ternary Relationship

 


Weak Entity Sets

- Key

[Fig 7] Keys

 

  - entity 유일하게 결정하는 Super key / minimalSuper key에서 Primary key-Alternate key를 결정한다

 

- Weak Entity Set Primary key 없는 entity set 말한다

- Weak Entity Set Primary Key Strong Entity Set 의해 형성된다 (stored not explicitly but implicit)

  - Weak Entity는 Strong Entity 없이 있을 수 없다

- Identifying Entity Set ([Fig 4] 같은 double diamond) 의존한다

- Weak Entity Set Discriminator(or Partial key) 속성들은 [Fig 4] 같이 점선 밑줄로 표시된다 -> Primary key

 


E-R 모델 예시

 

[Fig 8] E-R Diagram for a university enterprise

 


Extended E-R Features

- Specialization & Generalization

  - Specialization: 하향식으로 속성을 상속하는 하위 집단을 구성하며 설계한다 (ISA; "is a" 삼각형 컴포넌트로 묘사된다)

    -> primary key만 상속받을 경우, lower-lever, high-lever 두 가지에 접근하여 속성을 받아야 한다

    -> 모든 속성을 상속받을 경우, not required 중복이 일어날 수 있다 (특히 total일 때)

  - Generalization: 상향식 설계로, Specialization과 반대되는 개념이다

  - 이는 Super Entity(superclass) - Sub Entity(subclass) 로 구성된다

 

- Specialization & Generalization 제약 조건

  - 조건을 걸어 entity 생성 제약을 걸 수 있다 (condition-defined / user-defined)

  - Disjoint: entity가 하나의 lower-level entity set에 속한다 (entity들을 같은 삼각형에 연결)

    / Overlapping: entity가 두 개 이상의 lower-level entity set에 속할 수 있다

  - total: entity는 하나의 lower-level entity set에 속해야 한다

    / partial: entity는 여러 lower-level entity set에 속할 수 있다

 

[Fig 9] disjoint/overlapping & total/partial


- Total Summary

[Fig 10] Summary of E-R 1
[Fig 11] Summary of E-R 2

 


 UML and Other E-R Notations

- UML; Unified Modeling Language

  - 그래픽 모델링의 많은 구성 요소 (주로 객체 지향)

  - E-R Diagram과 비슷하지만, 몇몇이 다르다.

 

[Fig 12] ER vs UML

 

- Chen, IDE1FX, ...

[Fig 13.1]
[Fig 13.2] Chen / IDE1FX 

 

 


Reduction to Relation Schemas

이제는 E-R Diagram Table(관계형 모델) 구성해야 한다. 보통은 자동적으로 이루어진다

 

[Fig 14]  각  schema 는   고유한   이름을   가진   많은  columns 를   가진다

 

- Relationship Set 표현

  1. entity primary keys 구성한다. 이는 cardinality 상관 없이 항상 동작한다

  2. (one-to-many, many-to-one 이거나 many side total ) relationship set 생성하지 않고, one 측의 primary      key 다른 쪽에 추가한다

  일대일 관계 집합의 경우, 어느 쪽이든 "many" 있습니다. , entity set 해당하는 table 하나에 추가      attribute 추가할 있다

  ▪ many 쪽이 partial 경우, schema many 쪽에 해당하는 추가 attribute 바꾸면 null 값이 발생할 있다

  ▪ weak entity set identifying strong entity set 연결하는 relationship set schema 중복된다

 

- Composite, Multivalued Attributes

[Fig 15] Composite, Multivalued Attributes

 

    - multivalued attributes 무시하면, instructor schema 다음과 같다

     

instructor(
  ID,
  first_name,
  middle_initial,
  last_name,
  street_number,
  street_name,
  apt_number,
  city,
  state,
  zip_code,
  date_of_birth
)

 

  - multivalued attribute schema EM(엔티티-다중값) 상의 관계의 튜플에 매핑된다. ex) (222, 567-6940) and (222, 869-1641)

 


Design Issues

- attribute에 추가 정보를 허용하거나, 다수의 값이 있을 때 entity를 분리한다

- entity 간의 동작을 relationship set로 지정한다

- relationship attributes의 여부

- 여러 entitiessingle relationship에 참여하는 것은 n-ary relationship set으로 보여준다 (converting non-binary relationships to binary form)

  - 두 개의 partial binary relationship으로 나눌 수 있다 (그러나 proj_guide 같은 경우는 non-binary가 자연스럽다)

 

[Fig 16] Converting Non-Binary to Binary

반응형