Database Design
DB Lab. CUK 1
Data Modeling
• 데이터와 현실 설계
• 데이터 모델의 개념
• 개체 타입과 관계 타입
• ER 다이어그램
• 제약 조건
Database Design
DB Lab. CUK 2
데이터의 세계
현실 세계(개체)
개체 타입
속성
값
개념 세계(개념) 컴퓨터 세계(데이터)
레코드 타입
필드
값 특성
값 개체
값 사실
추상화 개념적 구조 논리적 구조 (데이터 모델)
변환 데이터 모델링 개념적
모델링
Database Design
DB Lab. CUK 3
데이터베이스와 현실 세계
논리적 구조 개념적 구조
저장 데이터베이스
현실 세계
개체
개념 세계 정보 모델링
일치성
데이터 모델링
데이타 구조화
컴퓨터 세계 데이터 구조화 개념적 모델링
Database Design
DB Lab. CUK 4
데이터 모델의 개념
A data model 은
?
– collection of concepts for describing data
A schema 는
?
– description of a particular collection of data, using the a given data model
The relational model of data is the most widely used model today.
– Main concept: relation, basically a table with rows and columns
– Every relation has a schema, which describes the columns, or fields.
Database Design
DB Lab. CUK 5
데이터 모델에 표시할 요소
구조(structure)
– 논리적으로 표현된 개체 타입들 간의 관계로서 데이터 구조 및 정적 성질을 표현
연산(operation)
– 데이터베이스에 저장된 실제 데이터를 처리하는 작업에 대한 명세로서 데이터베이스를 조작하는 기본 도구
제약조건(constraint)
– 데이터베이스에 저장될 수 있는 실제 데이터의 논리적인 제약조건
Database Design
DB Lab. CUK 6
개체 타입 (1/5)
개체 타입(entity type)
– 이름과 속성(애트리뷰트)들로 정의됨 – 개체 집합(entity set) :
특정 개체 타입에 대한 인스턴스 집합
속성(애트리뷰트)의 유형
– 단순 속성과 복합 속성
– 저장 속성과 유도(파생) 속성 – 널 속성
Database Design
DB Lab. CUK 7
개체 타입 (2/4)
주소
도 시(군,읍) 동(면)번지 우편번호
동(면) 번지 아파트번호
복합 속성(composite attribute)
– 몇 개의 기본적인 단순 속성들로 분해할 수 있는 속성
– 사용자가 때로는 복합 속성을 하나의 단위로 사용하고, 때로는 그 부속 속성 값을 참조하는 경우에 유용
– 복합 속성이 항상 전체로만 참조된다면 그것을 다시 부속 속성으로 분해할 필요가 없음
Database Design
DB Lab. CUK 8
유도(파생) 속성(derived attribute)
– 다른 속성의 값으로부터 계산된 속성
– 주민등록번호로부터 얻어진 나이, 성적으로부터 계산된 평균 성적, 원금, 예치기간, 이자율로부터 계산된 이자 – 유도 속성은 통계관련 엔티티 경우 이용되며, 일반
엔티티에서는 많이 사용되지 않음
– 유도 속성이 가지는 업무로직을 기술하여 데이터의
정합성이 유지되어야 하고, 단순 속성이 생성, 수정, 삭제될 때 유도속성도 함께 고려해야 됨
– ER 다이어그램에서 점선 타원으로 표현함
개체 타입 (3/4)
Database Design
DB Lab. CUK 9
널 속성(null attribute)
– 어떤 개체 인스턴스가 어느 특정 속성에 대한 값을 갖고 있지 않을 때 사용
– not applicable : ?
• 미혼인 사람의 배우자 이름
– unknown : ?
• missing: 값이 존재하지만 누락인 경우 학생 개체의 이름이 널인 경우
• not known: 값이 존재하는지 모르는 경우 취미 있는지 조차도 모르는 경우
개체 타입 (4/4)
Database Design
DB Lab. CUK 10
관계 타입(1/2)
교수 과목
시간 장소
강의
애트리뷰트를 가진 관계 타입
Database Design
DB Lab. CUK 11
관계 타입(2/2)
전체 참여(total participation)
– A-B 관계에서 개체 집합 B의 모든 개체가 A-B 관계에 참여
– ex) 학과 – 교수
부분 참여(partial participation)
– A-B 관계에서 개체 집합 B의 일부 개체만 A-B 관계에 참여
– ex) 과목 – 학생 (휴학생 허용 시)
Database Design
DB Lab. CUK 12
관계의 차수는 관계로 연결된 엔티티 타입들의 개수를 의미
실 세계에서 가장 흔한 관계는 두 개의 엔티티 타입을 연결하는 2진 관계
관계 타입의 특성( 1/2)
EMPLOYEE DEPARTMENT
PROJECT PART
SUPPLIER SUPPLIES
WORKS
1진 관계 2진 관계
3진 관계 n진 관계
SUPERVISES EMPLOYEE
Database Design
DB Lab. CUK 13
카디날리티 비율은 한 엔티티가 참여할 수 있는 관계의 수를 의미
두 개의 엔티티 E1과 E2 타입을 연결하는 2진 관계에서
1 : 1 관계 ?
예) 부부 사이의 배우자 관계
• 1 : N 관계 ?
예) 각 학생은 한 명의 지도교수가 정해지고, 각 지도교수는 여러 명의 학생들을 지도
• M : N 관계 ?
예) 각 학생은 여러 과목을 수강하고, 각 과목은 여러 명의 수강학생들이 있음
관계 타입의 특성(2/2)
Database Design
DB Lab. CUK 14
ER 다이어그램
1976. Peter Chen
ER 모델의 그래픽 표현
– 개체 타입 (entity type)
– 관계 타입 (relationship type) – 속성(attribute)
– 링크(link)
– 레이블(label) : 관계의 사상, 원소 수를 표현 일대일(1:1), 일대다(1:n), 다대다(n:m)
Database Design
DB Lab. CUK 15
ER 다이어그램 : 예제
교수
학생 등록 과목
지도 교수 강의
번호
교수
이름 전공 학과
시간
장소
학번 이름 주소 학년 과목
번호
과목
이름 학점 성적
Key 속성은?
Database Design
DB Lab. CUK 16
ER 다이어그램 : 예제
교수
학생 등록 과목
지도 교수 강의
번호
교수
이름 전공 학과
시간
장소
학번 이름 주소 학년 과목
번호
과목
이름 학점 성적
Key 속성은?
Database Design
DB Lab. CUK 17
ER 다이어그램 : 예제
교수
학생 등록 과목
지도 교수 강의
번호
교수
이름 전공 학과
시간
장소
학번 이름 주소 학년 과목
번호
과목
이름 학점 성적
? ?
?
? ?
?
Relationship ?
Database Design
DB Lab. CUK 18
ER 다이어그램 : 예제
교수
학생 등록 과목
지도 교수 강의
번호
교수
이름 전공 학과
시간
장소
학번 이름 주소 학년 과목
번호
과목
이름 학점 성적
n m
n 1 1
n
Relationship ?
Database Design
DB Lab. CUK 19
적은 노력으로 쉽게 배울 수 있고, 전문가가 아니어도 이해하기 쉬움
자연어보다 좀더 정형적이고, 구현에 독립적임
데이터베이스 설계자들이 최종 사용자들과 의사 소통을 하는데 적합함
ER 모델을 기반으로 만들어진 다수의 CASE 도구
- 예) ERWin, Visio, DataArchitect, PowerBuilder 등
이런 도구들은 ER 설계를 자동적으로 Oracle, Sybase 등의 데이터 정의어로 변환하고, 어떤 도구는 XML로 변환함
ER 모델링은 데이터베이스 설계를 위한 그래픽 표기법
ER Model(1/6)
Database Design
DB Lab. CUK 20
ER Model(2/6)
Entity
– Real-world object distinguishable from other objects – An entity is described using a set of attributes.
– Each entity has a key.
– Each attribute has a domain.
Employees ssn name
lot
Database Design
DB Lab. CUK 21
ER Model(3/6)
Relationship
– Association among two or more entities
– E.g., Adella works in pharmacy department
lot
dname
budget did
since name
Works_In Departments Employees
ssn
Database Design
DB Lab. CUK 22
ER Model(4/6)
budget
name
qty pid
name
Contract Part Dept
did
Supplier
sid
name
addr
Relationship
– An n-ary relationship R relates n entity sets E1 ... En; each relationship in R involves entities e1 E1, ..., en En.
Database Design
DB Lab. CUK 23
ER Model(5/6)
Relationship
– Same entity set could participate in different relationship sets.
Works_
In
Manage
Dept
Employee
Database Design
DB Lab. CUK 24
ER Model(6/6)
Relationship
– Same entity set could participate in different “roles” in same relationship set.
Reports_To lot name
Employees
subordinate supervisor
ssn
Database Design
DB Lab. CUK 25
Key Constraints
Consider Manages: each Department has at most one manager, according to the key constraint on Manages ?
dname
budget did
since
lot name
ssn
Manages
Employees Departments
Database Design
DB Lab. CUK 26
Key Constraints
Consider Manages: each Department has at most one manager, according to the key constraint on Manages ?
dname
budget did
since
lot name
ssn
Manages
Employees Departments
Database Design
DB Lab. CUK 27
Participation Constraints
Does every department have a manager?
– If so, this is a participation constraint:
the participation of Departments in Manages is said to be total.
• Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!) ?
dname
budget did
since
lot name
ssn
Manages
Employees Departments
Database Design
DB Lab. CUK 28
Participation Constraints
Does every department have a manager?
– If so, this is a participation constraint:
the participation of Departments in Manages is said to be total.
• Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!)
lot
name dname
budget did
since
name dname
budget did
since
Manages Departments
Employees ssn
Database Design
DB Lab. CUK 29
Weak Entities
A weak entity can be identified uniquely only by considering the primary key of another (owner) entity.
– Owner entity set and weak entity set must participate in a one-to- many relationship set (one owner, many weak entities).
– ?
lot name
pname age
Dependents Employees
ssn
Policy
1 n
Database Design
DB Lab. CUK 30
Weak Entities
A weak entity can be identified uniquely only by considering the primary key of another (owner) entity.
– Owner entity set and weak entity set must participate in a one-to- many relationship set (one owner, many weak entities).
– Weak entity set must have total participation in this identifying relationship set.
lot name
pname age
Dependents Employees
ssn
Policy
Database Design
DB Lab. CUK 31
ISA Hierarchies
Contract_Emps name
ssn
Employees
lot
hourly_wages
ISA
Hourly_Emps
contractid hours_worked
As in C++ or other PLs, attributes are inherited.
If we declare A ISA B,
every A entity is also considered to be a B entity.
Reasons for using ISA:
To add descriptive attributes specific to a subclass
Database Design
DB Lab. CUK 32
Specialization & Generalization
Specialization
– Top-down design process
– ISA relationship also referred to as superclass - subclass relationship.
Generalization
– Bottom-up design process
– Specialization and generalization are simple inversions of each other.
Database Design
DB Lab. CUK 33
ER 다이어그램 표기법
개체 타입
약한 개체 타입
관계 타입
약한 관계 타입
전체 참여 개체 타입
애트리뷰트
키 애트리뷰트
부분 키 애트리뷰트
복합 애트리뷰트
유도 애트리뷰트
Database Design
DB Lab. CUK 34
ERWin 등의 CASE 도구들에서는 새발(crow-feet) 표기법이 흔히 사용됨
새발 표기법에도 여러 가지 변형들이 존재함
ER 모델의 또 다른 표기법
Entity 1 Entity 2 Entity 3
• : 0을 의미
• : 1을 의미
• : 이상을 의미
Database Design
DB Lab. CUK 35
Object-Relational Data Models
Extend the relational data model by
including object orientation and constructs to deal with added data types.
Allow attributes of tuples to have complex types, including non-atomic values such as nested relations.
Provide upward compatibility with existing relational languages.
Database Design
DB Lab. CUK 36
XML: Extensible Markup Language
Defined by the WWW Consortium (W3C)
Originally intended as a document markup language not a database language
The ability to specify new tags, and to create nested tag structures made XML a great way to exchange data, not just documents
XML has become the basis for all new generation data interchange formats.
A wide variety of tools is available for parsing, browsing and querying XML documents/data.
Database Design
DB Lab. CUK 37
Summary(1/2)
ER model is popular for conceptual design
– Constructs are expressive, close to the way people think about their applications
Basic constructs:
–
entities, relationships, and attributes
Some additional constructs:
–
weak entities and ISA hierarchies
Note: There are many variations on ER model
Database Design
DB Lab. CUK 38
Summary(2/2)
Several kinds of integrity constraints can be
expressed in the ER model: primary key constraints,
foreign key constraints, participation constraints
Some constraints (notably, functional dependencies) cannot be expressed in the ER model.
Constraints play an important role in determining
the best database design for an enterprise. ER design is subjective. There are often many ways to model a given scenario!