본문 바로가기

공부 기록/Database

RDBMS _ 관계형 데이터베이스


Relational data model

수학에서의 Set : 중복을 허용하지 않는다, 순서는 중요하지 않다.
수학에서의 Relation : Cartesian product(곱집합, 카티션 곱)의 부분 집합, 튜플들의 집합

 

  • Relation(relation state) : 개념적인 의미 또는 실제 튜플(데이터)들의 집합을 의미한다.
  • Domain : set of atomic(더이상 나누어질 수 없는) values
  • Attribute : domain이 relation에서 맡은 역할의 이름
  • Tuple : 각 attribute의 값으로 이루어진 리스트. 일부 값은 NULL일 수 있다.

Relation schema

relation의 구조를 나타낸다.

relation 이름과 attributes 리스트로 표기된다.(e.g. STUDENT(id, name, grade, major))

attributes와 관련된 constraints도 포함한다.

* Degree of a relation : relation schema에서 attributes의 수

 

https://en.wikipedia.org/wiki/Cartesian_product

 

Cartesian product - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Mathematical set formed from two given sets In mathematics, specifically set theory, the Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs (a,

en.wikipedia.org

 


 

Relational database

  • relational data model에 기반하여 구조화된 Database
  • 여러 개의 relations로 구성된다.
  • relational database schema : relation schemas set + integrity constraints set

 


 

Relation

  • 중복을 허용하지 않는다. (값이 모두 동일한 튜플을 가질 수 없다.)
  • relation의 tuple을 식별하기 위해 attribute의 부분 집합을 key로 설정한다.
  • tuple과 attribute의 순서는 중요하지 않다. => 순서를 ordering 할 때에 여러 가지 방법을 이용할 수 있다.
  • 하나의 relation에서 attribute의 이름은 중복되면 안 된다.
  • attribute는 atomic 해야 한다. => composite attribute or multivalued attribute는 허용하지 않는다.

 


 

NULL

-  값이 존재하지 않는다.

-  값이 존재하나 아직 그 값이 무엇인지 알지 못 한다.

-  해당 사항이 없다.

여러 가지 의미로 표현될 수 있기 때문에 최대한 사용하지 않는 것이 좋다.

 


 

Key

  • superkey : relation에서 tuples를 unique하게 식별할 수 있는 attributes set
  • candidate key(key, minimal superkey) : 어느 한 attribute라도 제거하면 unique하게 tuples를 식별할 수 없는 superkey
  • primary key : relation에서 tuples를 unique하게 식별하기 위해 선택된 candidate key. 언더바로 표시한다.
  • unique key(alternate key) : primary key가 아닌 candidate keys
  • foreign key : 다른 relation의 primary key를 참조하는 attributes set

 

Constraints

relational database의 relations들이 항상 지켜줘야 하는 제약 사항

 

  • implicit constraints : relational data model 자체가 가지는 제약 사항 (e.g. relation은 중복되는 튜플을 가질 수 없다. relation 내에서는 같은 이름의 attribute를 가질 수 없다.)
  • schema-based constraints(explicit constraints) : 주로 DDL을 통해 schema에 직접 명시할 수 있는 제약 사항
    • domain constraints : attribute의 value는 해당 attribute의 domain에 속한 value여야 한다.
    • key constraints : 서로 다른 tuples는 같은 value의 key를 가질 수 없다.
    • NULL value constraints : attribute가 NOT NULL로 명시됐다면 NULL을 값으로 가질 수 없다.
    • entity integrity constraints : PK는 value에 NULL을 가질 수 없다.
    • referential integrity constraints : FK와 PK와 도메인이 같아야 하고, PK에 없는 values를 FK가 값으로 가질 수 없다.

 

'공부 기록 > Database' 카테고리의 다른 글

DML - 데이터 조작하기  (0) 2023.01.19
DDL - Table 생성하기, 목록 및 구조 확인  (0) 2023.01.19
Database 생성, 접속하기  (0) 2023.01.19
Database 사용자 생성과 권한 부여  (0) 2023.01.18
Database 개론  (0) 2023.01.18