set
- 서로 다른 elements를 가지는 collection
- 하나의 set에서 slements의 순서는 중요하지 않다.
- e.g.{1, 3, 11, 4, 7}
relation in mathematics
- subset fo Cartesian product
- set of tuples
relational data model 이해하기
- domain 정의하기(각 도메인에 속성을 지정하여 역할을 지정해 준다.)
- students_ids: 학번 집합, 7자리 integer 정수
- human_names: 사람 이름 집합, 문자열
- university_grades: 대학교 학년 집합, {1, 2, 3, 4}
- major_names: 대학교에서 배우는 전공 이름 집합
- phone_numbers: 핸드폰 번호 집합
relational data model
relational schema
- relation의 구조를 나타낸다.
- relation 이름과 attributes 리스트로 표기 된다.
- e.g. STUDENT(id, name, grade, major, phone_num, emer_phone_num) 와 같이 표기 한다.
- attributes와 관련된 constraints도 포함된다.
degree of arelation
- relation schema에서 attributes의 수
- e.g. STUDENT(id, name, grade, major, phone_num, emer_phone_num) = drgree 6
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의 이름이 중복되면 안된다.
- 하나의 relation에서 attribute의 순서는 중요하지 않다.
- attribute는 atomic해야 한다.(composite or multivalued attribute 허용 안됨) 더 이상 분류 되면 안된다.
NULL의 의미
- 존재하지 않는다.
- 값이 존재하지만 아직 그 값이 무엇인지 알지 못 한다.
- 해당 사항과 관련이 없다.
- 중의적 의미를 가질 수 있어 사용하지 않는 것이 좋다.
keys
- superkey
- relation에서 tuples를 unique하게 식별할 수 있는 attributes set
- e.g. PLAYER(id, name, team_id, back_number, birth_date)의 superkey는 {id, team_id, back_number, birth_date}, {id, name}, {name, team_id, back_number}, …etc
- candidate key
- 어느 한 attribute라도 제거하면 unique하게 tuples를 식별할 수 없는 superkey
- key or minimal superkey
- e.g. PLAYER(id, name, team_id, back_number, birth_date)의 cnadidate key는 {id}, {team_id, back_number}
- primary key
- relation에서 tuples를 unique하게 식별하기 위해 선택된 candidate key
- e.g. PLAYER(id, name, team_id, back_number, birth_date)의 primary key는 {id} or {team_id, back_number}
- unique key
- primary key가 아닌 candidate keys(primary key로 선택되지 못한 candidate keys)
- alternate key
- e.g. PLAYER(id, name, team_id, back_number, birth_date)의 unique key는 {team_id, back_number}
- foreign key
- 다른 relation의 PK(primary key)를 참조하는 attributes set
- e.g. PLAYER(id, name, team_id, back_number, birth_date)와 TEAM(id, name, manager)가 있을 때 foreign key는 PLAYER의 {team_id}가 TEAM{id}를 참조 하기 때문
constraints
relational database의 relations들이 항상 지켜줘야 하는 제약 사항
데이터 베이스가 일치된 형태로 일관성을 보장하기 위함
implicit constraints
- relational data model 자체가 가지는 constraints
- relation은 중복되는 tuple을 가질 수 없다.
- relation 내에서는 같은 이름의 attribute를 가질 수 없다.
schema-based constraints
- 주로 DDL(Data Definition Language)을 통해 schema에 직접 명시할 수 있는 constraints
- explicit constraints
- domain constraints: attribute의 value는 해당 domain에 속한 value여야 한다.
- key constraints: 서로 다른 tuples는 같은 value의 key를 가질 수 없다.
- NULL value constraint: attribute가 NOT NULL 로 명시되었다면 NULL을 값으로 가질 수 없다.
- entity integrity constraint: primary key는 value에 NULL을 가질 수 없다.
- referential integrity constraint: FK(foreign key)와 PK(primary key)와 도메인이 같아야 하고 PK에 없는 values를 FK가 값으로 가질 수 없다.