💽 DataBase

Relational Data Model과 Database

Set

서로 다른 Elements를 가지는 Collection
  • 하나의 Set에서 Elements의 순서는 중요하지 않다.
  • ex) {1, 3, 11, 4 ,7}

수학에서의 Relation

notion image
notion image
  • 이렇게 두개만 있으면 Binary Relation
  • Binary Relation은 카테시안 곱의 부분 집합

n개의 Set이 있을 때

notion image
  • n개이므로 n-ary Relation이라 함
  • 발생하는 조합들을 n-tuple이라 함

수학에서의 Relation

  • 카테시안 곱의 부분 집합
  • Tuple들의 집합

Relational Data Model에서의 Relation

notion image
  • Set들을 Domain이라 함
  • 이 전체를 Relation이라 함

Relational Data Model

Domain 정의하기

  • students_id : 학번, 7자리 integer
  • human_names : 사람 이름, 문자열
  • university_grades : 대학교 학년, {1, 2, 3, 4}
  • major_names : 대학교에서 배우는 전공 이름
  • phone_numbers : 핸드폰 번호
notion image

주요 개념

notion image

Relation Schema

Relation의 구조를 나타낸다.
  • Relation 이름과 Attributes 리스트로 표기된다.
  • ex) STUDENT(id, name, grade, major, phone_num, emer_phone_num)
  • Attributes와 관련된 Constraints도 포함한다.

Degree of Relation(릴레이션의 차수)

Relation Schema에서 Attributes의 수
ex) STUDENT(id, name, grade, major, phone_num, emer_phone_num) → degree 6

Relation(or Relation State)

어느 시점의 Tuple들의 집합

Relational Database

Relational Data Model에 기반하여 구조화된 Database
  • Relational Database는 여러 개의 Relations로 구성된다.

Relational Database Schema

Relation Schema Set + Integrity Constraints Set

Relation의 특징

  • 중복된 Tuple을 가질 수 없다. (Relation is Set of Tuples)
    • notion image
  • Tuple을 식별하기 위해 Attribute의 부분 집합을 Key로 설정한다.
    • notion image
  • Tuple의 순서는 중요하지 않다.
  • 하나의 Relation에서 Attribute의 이름은 중복될 수 없다.
  • 하나의 Tuple에서 Attribute의 순서는 중요하지 않다.
  • Attribute는 Atomic 해야 한다. (Composite or Multi Valued Attribute 허용 안됨)
    • 원자적인, 더 이상 나누어질 수 없는
    • notion image

Null의 의미

값이 존재하지 않는다.
  • 값이 존재하나, 아직 그 값이 무엇인지 알지 못한다.
  • 해당 사항과 관련이 없다.
notion image

Keys

Super Key

Relation에서 Tuple들을 Unique하게 식별할 수 있는 Attributes Set
notion image

Candidate Key

어느 한 Attribute라도 제거하면 Unique하게 Tuple들을 식별할 수 없는 Super Key
  • Key or Minimal Super Key
notion image

Primary Key

Relation에서 Tuple들을 Unique하게 식별하기 위해 선택된 Candidate Key
notion image

Unique Key

Primary Key가 아닌 Candidate Keys
  • Alternate Key
  • NULL 가능
notion image

Foreign Key

다른 Relation의 PK를 참조하는 Attributes Set
notion image

Constraints

Relational Database의 Relation들이 언제나 지켜야하는 제약 사항

Implicit Constraints

Relational Data Model 자체가 가지는 Constraints
  • Relation은 중복되는 Tuple을 가질 수 없다.
  • Relation 내에서는 같은 이름의 Attribute를 가질 수 없다.

Explicit Constraints(Schema-Based Constraints)

주로 DDL을 통해 Schema에 직접 명시할 수 있는 Constraints

Domain Constraints

Attribute의 Value는 해당 Attribute의 Domain에 속한 Value여야 한다.
notion image

Key Constraints

서로 다른 Tuple들은 같은 Value의 Key를 가질 수 없다.
notion image

Null Value Constraints

Attribute가 Not Null로 명시되어있다면, Null을 값으로 가질 수 없다.
notion image

Entity Integrity Constraints

Primary Key는 Value에 Null을 가질 수 없다.
notion image

Referential Integrity Constraints

FK와 PK와 Domain이 같아야 하고, PK에 없는 Value들을 FK가 값으로 가질 수 없다.
notion image

출처