STUDY/database

키(key)의 종류, constraints 종류

까미이모 2023. 11. 20. 21:40

super key

- relation에서 tuples를 unique하게 식별할 수 있는 속성들의 집합

 

candidate key

- 어느 한 attribute라도 제거하면 더이상 튜플들을 유일하게 식별할 수 없는 super key

- key or minimal superkey

- 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

 

unique key

- primary key가 아닌 candidate keys

- alternate key

- e.g. PLAYER(id(PK), name, team_id, back_number, birth_date)의 unique key는 {team_id, back_number}

 

foreign key

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


constraints란?

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

 

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

 

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

  1. domain constraints
    • attrebute의 value는 해당 attribute의 domain에 속한 value여야 한다.
  2. key constraints
    • 서로 다른 tuples는 같은 value의 key를 가질 수 없다.
  3. NULL value constraint
    • attribute가 NOT NULL로 명시됐다면 NULL을 값으로 가질 수 없다.
  4. entity integrity constraint
    • primary key는 value에 NULL을 가질 수 없다.
  5. referential integrity constraint
    • FK와 PK와 도메인이 같아야 하고 PK에 없는 values를 FK가 값으로 가질 수 없다.

 

참고: https://youtu.be/gjcbqZjlXjM?si=p3mjUX2oRN3naj4R

'STUDY > database' 카테고리의 다른 글

DB구축 예시  (1) 2023.11.21
SQL의 개념  (2) 2023.11.21
관계형 데이터베이스  (0) 2023.11.20
database schema 정리  (0) 2023.11.14
데이터베이스 기본개념  (1) 2023.11.14