기술(Tech, IT)/데이터베이스(Database)

[DB] Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

Daniel803 2023. 2. 16. 13:15

 Relational keys

: We need to be able to identify one or more attributes that uniquely identifies each tuple in a relation.

: 우리는 relation(관계) 속에서 각 튜플(row)를 고유하게 인식 또는 분간해주는 하나 또는 여러개의 속성이 필요한데 이를 relational keys라고 한다.

 Relational key의 종류는 아래와 같다.

 

1. Super Key(슈퍼키)

: An attribute, or set of attributes, that uniquely identifies a tuple within a relation.

: 하나 또는 여러 속성의 집합으로 각 튜플을 고유하게 구분해준다.

즉, Super Key의 핵심은 Uniqueness지 Minimality의 보장이 아니다.

 

2. Candidate Key(후보키)

: A superkey such that no proper subset is a superkey within the relation.

: Super Key 중에서 자신의 부분 집합이 또 다른 Super Key를 구성할 수 없는 Super Key이다

즉, Super Key 중에서 Uniqueness와 Minimality가 모두 보장되는 Key이다.

 

3. Primary Key(기본키)
: The candidate key that is selected to identify tuples uniquely within the relation.

: Candidate Key 중에서 튜플을 구분하기 위해 선택된 Key이다.

Primary Key는 Candidate Key 중에 유일하게 선택된 것이다.

 

4. Alternate Key(대체키)

: The candidate keys that are not selected to be the primary key are called alternate keys.

: Candidate Key 중에서 Primary Key로 선택되지 않은 Key들은 Candidate Key가 된다.

 

5. Foreign Key(외래키)

: An attribute, or set of attributes, within one relation that matches the candidate key of some (possibly the same) relation.

: 다른 Relation에 Candidate Key와 match(짝을 맞추는) 하나의 속성 또는 속성의 집합이다.

: Relationship을 이루고 있는 다른 Entity와의 연결을 인지하기 위해 표시해주고 1 to many(일 대 다) relationship에선 Foreign Key를 relation(테이블)에 표시해주는 것만으로 relationship을 위한 table을 SQL에서 따로 CREATE 해줄 필요가 없다.

 

참고

- Database Systems, A Practical Approach to Design, Implementation and Management Sixth Editio

- https://jerryjerryjerry.tistory.com/49

- https://moonibot.tistory.com/61