오뚝이개발자

[DB] CH2. 관계형 데이터 모델(Relational Model) 본문

CS 기초/DB

[DB] CH2. 관계형 데이터 모델(Relational Model)

땅어 2020. 10. 28. 17:45
728x90
300x250

 

관계형 데이터 모델이란?

  • 논리적인 relation 구조로 구성
  • 사용자는 원하는 데이터(what)만 명시하고 어떻게(how) 찾을 것인지를 명시할 필요 X
  • DB의 physical level과 logical level을 구분 -> 데이터 독립성 향상 + 단순한 구조

용어 정리

Example of Relation

  • Relation : 2차원 구조의 테이블로 된 정보저장 형태
    • 관계형 모델에서 DB는 이러한 relation이 여러개 모여있는 것
  • Attribute : 테이블에서 데이터들의 속성값(ID, name, dept_name, salary)
    • attribute value는 atomic 해야 함(예컨대, 전화번호라면 지역번호로 split하면 X, 그 자체로 non-atomic하게 다루어야 함)
  • Tuple(=Record) : 테이블에서 하나의 행
  • Domain : attribute가 취할 수 있는 값의 집합
    • "null"은 모든 domain의 member
  • Cardinality(기수) : 튜플 수
  • Degree(차수) : attribute 수

Relation schema

  • A,B,C,D의 속성이 있을 때, R=(A,B,C,D)처럼 나타내는 것을 relation schema라 한다.

키(key)의 종류

  • super key : tuple을 unique하게 구분해주는 속성의 집합(유일성)
  • candidate key : super key 중 minimal(유일성 + 최소성)
  • primary key : candidate key 중 선택된 하나를 primary key라고 함
  • foreign key : 한 relation의 속성 중 다른 relation의 primary key가 되는 것
    • 예컨대, relation r1의 A라는 속성이 relation r2의 primary key라면 A는 r1에서 r2를 참조하는 foreign key이다. 이 때, r1을 referencing relation이라 하고 r2를 referenced relation이라 한다.

예컨대, 대학 관련 DB에서 instructor=(ID, NAME)이라면, superkey={ID},{ID,NAME}이고 candidate key={ID}이다.

Foreign key constraint(외래키 무결성, 참조무결성)란?

  • foreign key와 관련해서 하나의 relation에서 등장하는 value는 다른 relation에도 반드시 존재해야 함
  • 예) instructor=(ID, name, dept_name, salary), department=(dept_name, building, budget)일 때, instructor의 dept_name에 등장하는 value는 department의 dept_name에 존재해야 한다.(vice versa)

Natural join

Natural join example(natural join은 cartesian->selection->projection 순으로 operation을 조합해 구현 가능)

참고자료

728x90
300x250
Comments