[DB] relation data model 개념 및 특징

김태준·2023년 11월 9일

데이터베이스

목록 보기
2/4

relational data model?

  • domain : set of atomic values
  • domain name : domain 이름
  • attribute : domain이 relation에서 맡은 역할 이름
  • tuple : 각 attribute의 값으로 이루어진 리스트, 일부 값은 NULL일 수 있다.
  • relation : set of tuples
  • relation name : relation 이름

student relation

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

relation schema

  • relation의 구조를 나타낸다.
  • relation 이름과 attributes리스트로 표기된다.
  • e.g. STUDENT(id,name,grade,major,phone_num,emer_phone_num)
  • attributes와 관련된 constraints도 포함된다.

degree of a relation

  • relation schema에서 attributes의 수
  • e.g.STUDENT(id,name,grade,major,phone_num,emer_phone_num) -> degree 6

relational database?

  • relational data model에 기반하여 구조화된 database
  • relational database는 여러 개의 relations로 구성된다.

relational database schema?

  • relation schemas set + integrity constraints set

relation의 특징들

  • relation은 중복된 tuple을 가질 수 없다.
  • relation의 tuple을 식별하기 위해 attribute의 부분 집합을 key로 설정한다.
  • relation에서 tuple의 순서는 중요하지 않다.
  • attribute는 atomic해야 한다. (composite or multivalued attribute 허용 안됨)

keys?

- superkey

relation에서 tuples를 unique하게 식별할 수 있는 attributes set 유일성O, 최소성X
e.g. PLAYER(id,name,team_id,back_number,birth_date)의 superkey는 {id,name,team_id,},{id,name},{name,team_id}... etc

- candidate key

어느 한 attribute라도 제거하면 unique하게 tuple를 식별할 수 없는 super key
e.g. PLAYER(id,name,team_id,back_number,birth_date)의 candidate key는 {id},{team_id,back_number}

- primary key

relation 에서 tuples를 unique하게 식별하기 위해 선택된 candidate key
e.g. PLAYER(id,name,team_id,back_number,birth_date)의 candidate key는 {id} or {team_id,back_number}

- unique key or alternate key

primary key가 아닌 candidate keys

- foreign key

다른 relation의 PK를 참조하는 attributes set

constraints?

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

constraints 종류

implicit constraints

  • relational data model 자체가 가지는 constraints
  • relation은 중복되는 tuple을 가질 수 없다.
  • relation 내에서는 같은 이름의 attribute를 가질 수 없다.

schema-based constraints or explicit constraints

  • 주로 DDL을 통해 schema에 직접 명시할 수 있는 constraints

schema-based constraints 종류

domain constraints

  • attribute의 value는 해당 attribute의 domain에 속한 value여야 한다.

key constraints

  • 서로 다른 tuples는 같은 value의 key를 가질 수 없다. (기본 키 중복X)

NULL value constraints

  • attribute가 NOT NULL로 명시됐다면 NULL을 값으로 가질 수 없다.

entity integrity constraint

  • primary key는 value에 NULL을 가질 수 없다.

referential integrity constraint

  • FK와 PK와 도멘이 같아야 하고 PK에 없는 values를 FK가 값으로 가질 수 없다.
profile
Java_Spring_JPA_DB

0개의 댓글