관계형 DB
: relational data model을 통해 구조화된 DB
RDBMS의 DB와 테이블,
엑셀의 파일과 시트/테이블은
데이터 구조화와 저장을 위한 개념으로 유사
데카르트 곱
Cartesian product A X B = {(a, b) | a∈A and b∈B}
binary relation ⊆ A X B
n-ary relation ⊆ X₁ x X₂ x X₃ x ... x Xₙ
domain: set of atomic values
domain name: domain 이름
attribute: domain이 relation에서 맡은 역할 이름
tuple: 각 attribute의 값으로 이루어진 리스트. 일부 값은 NULL 일 수 있다
relation: set of tuples (또는 relation state 인 경우도 있음)
relation name: relation 의 이름
relation schema
- relation 의 구조를 나타낸다
- relation 이름과 attributes 리스트로 표기된다
- attribute 와 관련된 constraints 도 포함한다
degree of a relation
- relation schema 에서 attributes 의 수
relational database
- relational data model 에 기반하여 구조화된 database
- relational database 는 여러 개의 relations 로 구성된다
relational database schema
- relational schemas set + interity constraints set
relation 은 중복된 tuple 을 가질 수 없다
(relation is set of tuples)
relation 의 tuple 을 식별하기 위해 attribute 의 부분 집합을 key 로 설정한다
relation 에서 tuple 의 순서는 중요하지 않다
하나의 relation 에서 attribute 의 이름은 중복되면 안 된다
하나의 tuple 에서 attribute 의 순서는 중요하지 않다
attribute 는 atomic 해야 한다
(composite 또는 multivalued attribute 는 허용 안됌)
여러 의미로 사용될 수 있기에 최대한 NULL 을 자제하는 게 좋다
슈퍼키(superkey)
- relation 에서 tuples 를 unique 하게 식별할 수 있는 attributes set
후보키(candidate key)
- key 또는 minimal superkey 라고도 함
- 어느 한 attribute 라도 제거하면, unique 하게 tuples 를 식별할 수 없는 /super key/
기본키(primary key)
- relation 에서 tuples 를 unique 하게 식별하기 위해 선택된 candidate key
- attribute 수가 적은 걸로 선택하는 게 편함
- 대체로, 이름 밑에 언더바("_")가 있음
고유키(unique key) 또는 대체키(alternate key)
- 기본키(primary key)로 선택되지 않은, 후보키(candidate key)
외래키(foreign key)
- 다른 relation 의 PK(Primary Key)를 참조하는 attributes set
implicit constraints
- relational data model 자체가 가지는 constraints
- relation 은 중복되는 tuple 을 가질 수 없다
- relation 내에서는 같은 이름의 attribute 를 가질 수 없다
explicit constraints (또는 schema-based constraints)
- 주로 DDL을 통해 schema 에 직접 명시할 수 있는 constraints
explicit constraints 종류
- domain constraints
- attribute 의 value 는 해당 attribute 의 domain 에 속한 value 여야 한다.
- key constraints
- 서로 다른 tuples 는 같은 value 의 key 를 가질 수 없다
- NULL value constraint
- attribute 가 NOT NULL 로 명시됐다면 NULL 을 값으로 가질 수 없다
- entity integrity constraint
- primary key 는 value 에 NULL 을 가질 수 없다
(여러 tuples 이 NULL 값을 가진다면, 더이상 tuple을 유니크하게 식별하지 못하기 때문)
- referential integrity constraint
- FK 와 PK 와 도메인이 같아야 하고,
PK 에 없는 values 를 FK 가 값으로 가질 수 없다