수학에서의 relation
set
ㄴ 서로 다른 elements를 가지는 collection
ㄴ 하나의 set에서 elements의 순서는 중요하지 않다.
ex) {1, 3, 10, 4, 7}
A× B= {(a,b)∣ a∈ A,b∈ B}
relation (table) 아래의 정보의 전체를 나타냄
attribute 속성 = id, name, grade, phone_num
tuple 데이터 리스트 = 1 손흥민 1 010-1234-5678, 2 박지성 2 010-5678-1234
id | name | grade | phone_num |
1 | 손흥민 | 1 | 010-1234-5678 |
2 | 박지성 | 2 | 010-5678-1234 |
relational data model
주요 개념 | 설명 |
domain | set of atomic values |
domain name | domain 이름 |
attribute | domain이 relation에서 맡은 역할 이름 |
tuple | 각 attribute의 값으로 이루어진 리스트, 일부 값은 NULL일 수 있다. |
relation | set of tuples |
relation name | relation의 이름 |
relation schema
ㄴ relation의 구조를 나타낸다.
ㄴ relation 이름과 attributes 리스트로 표기된다.
ex) STUDENT(id, name, grade, phone_num)
- attributes와 관련된 constraints도 포함된다.
degree of a relation
ㄴ relation schema에서 attributes의 수
ex) STUDENT(id, name, grade, phone_num) -> degree 4
relation ( or relation state ) => 개념적인 relation 혹은 tuple들의 집함 ( relation state ) 문맥에 따라 구분 필요
relational database
ㄴ relational data model에 기반하여 구조화된 database
ㄴ relational database는 여러 개의 relations로 구성된다.
relational database schema
ㄴ relation schemas set + integrity constraints set 으로 구성됨
relation의 특징
ㄴ relation은 중복된 tuple을 가질 수 없다. ( relation is set of tuples )
ㄴ relation의 tuple을 식별하기 위해 attribute의 부분 집합을 key로 설정한다.
ㄴ relation에서 tuple의 순서는 중요하지 않다.
ㄴ 하나의 relation에서 attribute의 이름은 중복되면 안된다.
ㄴ 하나의 tuple에서 attribute의 순서는 중요하지 않다.
ㄴ attribute는 atomic 해야 한다. ( composite or multivalued attribute 허용 안됨 )
NULL의 의미
ㄴ 값이 존재하지 않는다.
ㄴ 값이 존재하나 아직 그 값이 무엇인지 알지 못한다.
ㄴ 해당 사항과 관련이 없다.
- 최대한 안쓰는게 좋다.
superkey
ㄴ relation에서 tuples를 unique하게 식별할 수 있는 attributes set
ex) PLAYER(id, name, team_id, back_number, birth_date) 의 superkey는
-> { id, name, team_id, back_number, birth_date }, { id, name }, { name, team_id, back_number } ... 등등
candidate key
ㄴ 어느 한 attribute라도 제거하면 unique하게 tuples를 식별할 수 없는 super key
ㄴ key or minimal superkey 라고 부르기도 한다.
primary key
ㄴ relation에서 tuples를 unique하게 식별하기 위해 선택된 candidate key
ex) PLAYER(id, name, team_id, back_number, birth_date)의 primary key는
-> { id }, { team_id, back_number }
unique key
ㄴ primary key가 아닌 canmdidate keys => alternate key 라고도 한다.
ex) PLAYER(id, name, team_id, back_number, birth_date)의 unique key는
-> id가 primary key가 된다면 => { team_id, back_number }
foreign key
ㄴ 다른 relation의 PK를 참조하는 attributes set
PLAYER(id, name, team_id, back_number, birth_date)
TEAM(id, name, manager) 가 있을 때
foreign key는 PLAYER의 { team_id } => PLAYER.team_id -> TEAM.id
constraints
ㄴ relational database의 relations들이 언제나 항상 지켜줘야 하는 제약 사항
implicit constraints
ㄴ relational data model 자체가 가지는 constraints
ㄴ relation은 중복되는 tuple을 가질 수 없다.
ㄴ relation 내에서는 같은 이름의 attribute를 가질 수 없다.
schema-based constraints
ㄴ 주로 DDL을 통해 schema에 직접 명시할 수 있는 constraints
ㄴ explicit constraints 라고도 부름
domain constraints
ㄴ attribute의 value는 해당 attribute의 domain에 속한 value여야 한다.
id | name | grade |
1 | 홍진호 | 4 |
2 | 손흥민 | 100 (위반) |
3 | 박지성 | 2 |
key constraints
ㄴ 서로 다른 tuples는 같은 value의 key를 가질 수 없다.
id ( PK ) | name | graede |
1 ( 중복 ) | 홍진호 | 4 |
1 ( 중복 ) | 손흥민 | 2 |
3 | 박지성 | 1 |
NULL value constraint
ㄴ attribute가 NOT NULL로 명시 됐다면 NULL을 값으로 가질 수 없다.
entity integrity constraint
ㄴ primary key는 value에 NULL을 가질 수 없다.
referential integrity constraint
ㄴ FK와 PK와 도메인이 같아야하고 PK에 없는 values를 FK가 값으로 가질 수 없다.
'데이터베이스' 카테고리의 다른 글
Structured Query Language ( SQL ) (0) | 2024.02.11 |
---|---|
Database System 관련 용어 (0) | 2024.02.09 |