Informal Definitions

Example of Relation

Relation은 table처럼 보인다. 각 row 줄을 tuple이라고 한다. Entity와 같은 개념이라고 보면 된다. Tuple이 가지는 attributes 중 유니크하게 구별해주는 attribute를 key라고 한다. 위의 예시에서는 SSN이 Key가 된다.

 

Formal Definitions - Schema

R(A1, A2, ..., An)

Relation은 위와 같이 표현한다. R은 relation의 이름이고, An은 attribute의 이름이다. 각 attribute가 가질 수 있는 value의 범위를 domain이라고 한다.

 

Formal Definitions - Tuple

<123123, "John", "101 Main St. Atlanta">

Tuple은 value의 ordered set으로 보통 표시한다. 3-tuples라고 말한다. Relation은 set of tuples이다.

<123123, "a">, <121212, "b">, <111111, "c">

위와 같은 형태는 3개의 2-tuples라고 할 수 있다.

 

Formal Definitions - Domain

Data-type과 format defined를 가지고 있다.

 

Formal Definitions - Relation State

Relation state는 attributes들의 가능한 모든 조합의 부분집합이다. 어떤 시간에 relation이기 때문이다.

 

Definition Summary

Informal Terms Formal Terms
Table Relation
Column Header Attribute
All possible column values Domain
Row Tuple
Table definition Schema of a Relation
Populated Table State of the Relation

 

Characteristics of Relations

r(R)에서 tuple의 순서는 중요하지 않다. 다만 attribute의 순서는 table(relation)이 atomic하게 정해져 있기 때문에 중요하다.

*self-describing에서는 name과 value를 같이 저장하기 때문에 순서가 중요하지 않다.

*null에 대해서는 unkonwn, not available, inapplicable의 다른 상태일 수 있다.

*tuple의 attribute는 "tuple[attribute]"를 이용해 접근할 수 있다.

 

Constraints

Inherent or Implicit constraints Schema-based or Explicit constraints Application based or semantic constraints
data model에 의한 제약을 말한다. domain 제약, null 제약, key 제약, reference 제약, entity 제약을 말한다. 비즈니스 제약조건으로 DB가 아닌 응용프로그램에서 제한을 만들어서 사용하는 것을 말한다.

 

Relational Integrity Constraints (Explicit constraints)

  • Key constraints
  • Entity integrity constraints
  • Referential integrity constraints
  • Domain constraint
  • Null constraint
Key constraint Entity integrity constraints
Tuple끼리 구분이 가능한 (primary) key가 있어야 한다. 즉 PK는 중복이 허용되지 않는다.  Primary key는 항상 값이 존재해야 하는 제약이다. Null이 되면 안된다.
Referential integrity constraints Null constraint
Relation에서 foregin key와 primary key간의 연결이 올바르게 유지되고 있어야 한다. Null 값이 가능한 경우에만 사용해야 하는 제약이다. 잘못된 정보도 null로 표현이 되기 때문에, 표현 허용여부를 아는 것이 중요하다.
Domain constraint  
Attribute의 domain에 알맞은 값이 들어와야 한다.  

 

Key constraints

Superkey Key
Tuple끼리 구분 가능한 attribute의 조합이다. Superkey의 minimal로, tuple끼리 구분할 수 있게 해주는 최소의 attribute이다. 여러개도 가능하다.
Candidate key Primary key
간단하게 Key라고 보면 된다. Unique하다는 설정을 넣을 수 있다. Candidate key 중에 선택된 key이다. 복수일 수 있다. 

 

Relational DB schema

"R1, R2, ..., Rn"을 relation schema라고 하며, 이것들의 조합을 DB schema라고 한다. "S = {R1, R2, ..., Rn}"으로 표기한다. Relational DB state는 "S = {r1, r2, ..., rn}"라고 한다.

 

Populated DB state

INSERT, DELETE, MODIFY에 의해 생성된 모든 relation state을 말한다.

 

Update Operations on Relations

Integrity가 침해받을 경우, 다음의 대처가 이루어지게 된다.

  1. Cancel the operation
  2. Perform the operation, but inform it
  3. Trigger additional updates

 

Possible violations for each Operation

INSERT
Domain constraint
New tuple이 domain에서 어긋난 value를 가지고 있을 수 있다.

Key constraint
Key attribute에 해당하는 new tuple의 value가 중복될 수 있다. 중복되면 안된다.

Null constraint

Null이 들어가면 안되는 곳에 들어갈 수 있다.

Referential integrity
New tuple의 foreign key가 존재하지 않는 primary key value를 참조할 수 있다.

Entity integrity

New tuple의 PK가 null이면 안된다.
DELETE
Referential integrity
Primary key가 지워지면, 이걸 참조하는 다른 tuple의 참조 무결성이 깨지게 된다.
해결책으로는 RESTRICT(delete 거절), CASCADE(foreign key에 새로운 primary key를 만들어 준다), SET NULL의 방법이 있다.
MODIFY
기본적으로 INSERT, DELETE에서 확인했던 것들을 모두 확인하면 된다.

Updating PK
DELETE에서 했던 과정을 반복한다.

Updating FK
Referential integrity를 위반할 수 있다.

Updating ordinary attribute(PK, FK, normal)
Domain constraint를 위반할 수 있다.

 

ER to Relational Mapping Algorithm

  1. Mapping of Regular Entity type
  2. Mapping of Weak Entity type
  3. Mapping of Binary 1:1 Relation type
  4. Mapping of Binary 1:N Relation type
  5. Mapping of Binary M:N Relation type
  6. Mapping of Multi-valued attributes
  7. Mapping of N-ary Relationship type

 

Summary of Mapping constructs and constraints

ER model Relational model
Entity type Entity relation
1:1 or 1:N relationship type Foreign key
M:N relationship type Relationship realtion and 2 foreign key
n-ary relationship type Relationship realtion and N foreign key
Simple attribute Attribute
Composite attribute Set of simple component attributes
Multi-valued attribute Relation and foreign key
Value set Domain
Key attribute Primary key