본문 바로가기

데이터베이스설계

[데이타베이스설계] E-R-Model

  • 7-1) 디자인 단계 (Design phases)
  • 7-2) ERD (Entity Realationship Model)
  • 7-3) Cardinality Constraints
  • 7-4) 전체, 부분 참여 (Total and Partial Participation)
  • 7-5) 약한 개체 (Weak Entity Sets)
  • 7-6) UML (Unified Modelling Language)

 

 


 

  • 7-1) 디자인 단계 (Design phases)

초기단계 (Initial phase)

데이터베이스 사용자 관점에서의 데이터 요구를 완벽하게 characterize(특성화) 짓는다.

 

두 번째 단계 (Second phase)

data model을 고른다. 데이터베이스 개념 스키마에 요구사항을 변환하여 넣는다.

개념 스키마를 완전히 개발하면 기능 요구사항이 뭔지 알 수 있다. (* 개념 스키마 : 전체적인 view)

 

마지막 단계 (Final phase)

추상적인 데이터 모델에서 데이터베이스 구현으로 진행한다.

        - Logical design : 데이터베이스 스키마를 결정한다. 이때 좋은 relation 스키마를 찾아야한다.

        (비지니스 decision : 데이터베이스 레코드에 어떤 속성이 있어야 할 지 / CS decision : 어떤 relation Database?)

        - Physical design : 데이터베이스의 물리적 결정

 

 

데이터베이스를 design할 때는 다음 두가지를 피해야 한다.

        - Redundancy(중복) : 정보가 중복되면 데이터와 데이터 복사본 간에 불일치로 이루어질 수 있다.

        - Incompleteness(불완전성) : 잘못된 설계는 모델링하기 어렵거나 불가능하게 만든다.

 

 

 


 

  • 7-2) ERD (Entity Relationship Model)

ER data Model은 데이터베이스의 전체적인 논리 구조를 나타내는데 용이하게 하기위해 만들어졌다.

ERD (Entity Relationship Diagram)은 ER data Model을 그래픽으로 표현한 것이다.

ER data Model은 3가지 개념으로 이루어져있다. (Entity sets, Relationship sets, Attributes)

 

Entity sets: 같은 테이블의 있는 튜플들의 집합 (ex. person집합, company집합, ...)

Entity란 하나의 객체이다. 즉, 테이블에서 하나의 튜플이다.

Entity sets
Entity sets in ERD

Entity sets은 직사각형으로 표현되고 속성들은 직사각형 안에 리스트된 것들이다.

이 중 밑줄이 있는 속성은 primary key속성이다.

 

 

Relationship sets

relationship type은 entity type 사이의 연관관계를 나타낸다.

Example 1

아래 Example 2와 같이 relationship set는 어떤 속성으로 연관되어 묶일 수도 있다.

Example 2

ERD에서 realationship set는 diamond형태로 Entity sets 사이를 선으로 연결한다.

Relationship sets in ERD
Relationship sets with Attributes

Role

entity가 relationship에서 수행하는 기능을 role이라고 한다.

ERD에서 entity의 기능은 entity와 relationship을 연결하는 선 위에 표시한다.

Roles in ERD

 

Relationship set의 종류

 

1) Binary relationship

두 entity sets사이의 존재하는 관계를 binary relationship이라 하며 대부분의 관계들이 이것이다.

 

2) Ternary relationship

instructor가 student에게 project를 project guide하면 이들은 아래와 같이 삼항 관계를 갖는다.

Example 1

 

 

Attributes

Attributes는 ERD에서 타원으로 표현하며 종류는 아래와 같다.

        - Simple, Composite attributes : simple은 단일속성, composite은 여러 속성값으로 이루어진 속성이다 (ex. 주소)

        - Single-valued, multivalued attributes : 1개의 value를 가질 수 있으면 Single, 2개 이상의 값을 가지면 multi

        - Derived attributes : 다른 속성값들로부터 계산되어 구해질 수 있으면 derived이다. (ex. 나이, 총 가격)

        - Key attribute : primary key인 attribute이다. 밑줄로 표현된다.

 

 

Domain

attribute에 허용된 value 집합을 Domain이라 한다.

 

 

 


 

  • 7-3) Cardinality Constraints

relationship이 존재하는 두 entity사이에 한 entity에서 다른 entity 몇개의 개체와 대응되는지 나타내는 제약조건이다.

Mapping Cardinality의 종류는 다음과 같다.

        - One to one : 1대1 대응

        - One to many : 1대다 대응

        - Many to one : 다대1 대응

        - Many to many : 다대다 대응

Mapping Cardinality Example 1
Mapping Cardinality Example 2

이때 어떤 entity 들은 서로 mapping이 안 될 수도 있다.

 

  • ERD에서의 Cardinality constraints

ERD에서 화살표(->)는 1개 대응을 뜻하고 선(-)은 여러개 대응을 뜻한다. 

 

1) One-to-one relationship

1대1

 

2) One-to-many relationship

1대다

instructor에 화살표, student에 선이 있으므로 instructor는 1개일때 student는 여러개 연관될 수 있다는 뜻이다.

여러 student는 1개의 instructor와 mapping.

 

3) Many-to-one relationship

Many-to-one

여러 instructor는 한 개의 student와 mapping.

 

4) Many-to-many relationship

Many-to-many

여러 instructor는 여러 student와 mapping.

 

 

 


 

  • 7-4) 전체, 부분 참여 (Total and Partial Participation)
  • 전체 참여 (Total Participation)

전체 참여는 두줄로 표현하고 예시는 아래와 같다.

Total Participation

student와 관계가 없는 instructor가 존재할 수는 있지만 모든 student는 무조건 instructor와 관계가 있어야한다.

 

  • 부분 참여 (Partial Participation)

부분 참여란 어떤 entities는 관계에 참여 안할 수 있다는 뜻이다.

위의 Total Participation 예시에서 어떤 instructor는 student와 관계를 안가지고 있을 수 있다.

 

 

구조적 제약

선에 mininum, maximum cardinality가 있을 수 있다.

        - minimum=1 : 전체 참여를 뜻한다.

        - maximum=1 : cardinality에서 화살표를 뜻한다 (상대랑 최대 한개가 mapping

        - maximum=* : no limit을 뜻한다.

위의 예시 : 학생은 반드시 한명의 instructor만 갖는다.

instructor는 0혹은 그 이상의 student와 관계를 갖는다.

(?? 이상하게 cardinality constraint와 뜻하는 바가 반대)

 

 

 


 

  • 7-5) 약한 개체 (Weak Entity Sets)

entity type은 반드시 key 속성을 가져야 한다. 하지만 key 속성이 정의되지 않는 개체들이 있다. 이를 약한 개체라 한다.

weak entity sets은 primary key를 형성하기에 충분한 attribute들이 존재하지 않는다.

(즉, 각각의 entity를 모두 확실하게 구분지을 수 있는 primary key가 없고 현재 속성으로는 중복되는 개체들도 존재)

primary key를 갖고 있는 entity sets은 strong entity sets이라 한다.

Weak entities는 primary key가 없기 때문에 단독으로 존재할 수 없고 다른 개체에 의존해서 존재한다.

weak entities들은 따라서 자신들의 owner entity에 대해 전체 참여를 한다. (모든 weak은 strong과 관계가 있어야함)

그래도 튜플을 구분하기 위해 Partial key는 가지고 있다.

Weak Entity Sets

1개의 course는 여러 섹션으로 존재할 수 있고 section은 반드시 관계를 갖고 있어야 한다.

ERD에서 weak entity sets은 두 개의 직사각형을 중첩한 형태로 표현한다.

weak entites sets에 있는 속성은 ----(점선)으로 표시하고 primary key는 strong entites sets에 있다.

 

Extended E-R Features

더 복잡한 data때문에 ER model을 향상시키기 위해 향상된 ER model이 개발되었다.

        - Specialization

        - Generalization

        - Aggregation

 

1) Specialization

하나의 entity가 두개의 하위 level entity로 나눠지는 top-down approach를 specialization이라 한다.

하위 level entity는 상위 level entity의 속성과 relationship participation을 모두 상속받는다.

Specialization

 

2) Generalization

같은 feature를 갖는 하위 level entity들을 bottom up으로 결합하는 것을 Generalization이라 한다.

Specialization과 Generalization은 접근법과 시작점의 차이이다.

 

3) Aggregation

어떤 entities들 사이의 관계가 entity로 여겨질때 Aggregation을 사용한다.

Aggregation

Center과 Course사이의 relationship이 Visitor입장에서 Entity로 동작한다.

Visitor는 오직 Center에만 enquire하거나 Course에만 enquire할 수 없고 둘 모두에게 enquire해야한다.

 

 

Summary
Summary

 

 

 


 

  • 7-6) UML (Unified Modeling Language)

UML은 language를 modelling하기위함이다. system이 동작하는 과정을 시각화하기 위해 설계된다.

UML Class Diagram이 E-R Diagram과 대응되지만 몇가지가 다르다.

UML Diagrams 종류

        - Class Diagram, Object Diagram, Composite Structure Diagram

        - Component Diagram, Deployment Diagram, Package Diagram

ERD vs UML Class Diagram 1

 

ERD vs UML Class Diagram 2