Background
Relational Model
a data model
describes data (relation, relation schema, tuples, attributes, domains, keys)
describes constraints
relation model은 predicate logic과 set theory를 기반으로 함
Predicate Logic (술어 논리)
컴퓨터가 이해하기 위한 표현 방식
사람을 위한 표현 방식인 propositonal logic, sentential logic과 구분됨
first argument: a subject
second argument: its possessive
(ex) "학번이 S1인 학생의 이름은 홍길동이다" 라는 현실세계의 정보를 술어논리 표현으로 표현하면
- 학번(S1) ⋀ 이름(홍길동)
- 이름(S1, 홍길동)
Set Theory
집합의 기본적인 성질 두 가지: 원소 중복 불가 & 원소들 간 순서 무관
단, multi set은 중복되는 원소를 가질 수 있음
relational model은 set을 기반으로 하기 때문에 중복되는 원소를 가질 수 없지만, SQL은 multi set을 기반으로 해 중복되는 원소를 가질 수 있으므로 주의
Basic Structure
Relation = Relation Schema + Relation Instance

attribute = SQL의 column
domain: 각 attribute가 갖는 값의 범위를 정한 것
instance: 실제 data
tuple = SQL의 row
relation = n개의 tuples
regal relation: 모든 instance의 각 값들이 domain 내에 있고, 중복된 tuple이 없는 것
relation schema R = relation r의 attribute들의 집합
relation schema에 붙이는 이름은 대문자로 시작함
Relational Model의 4가지 속성
1. every tuple must be unique
2. tuples 순서 무관
3. attributes 순서 무관
4. attribute 값들은 atomic
Attributes
domain: 해당 attribute가 가질 수 있는 allowed values의 집합
mutlivalued attribute: 두 개 이상의 값을 갖는 attribute
composite attribute: 두 개 이상의 component로 구성된 attribute

(ex) 위 사례에서, 주소는 composite attribute / 연락처는 multivalued attribute
attribute 값은 쪼갤 수 없지만, mutivalued/composite attribute는 not atomic
null value
null은 모든 domain의 원소
null을 사용하는 2가지 경우
- 그 값이 존재하지만, 아직 모르는 경우
- 그 값이 존재하지 않는 경우 (해당사항 없음)
Keys
key: relation schema의 부분집합. attribute들의 조합.
superkey
어떤 tuple을 특정할 수 있는 attribute(s)
candidate key
여러 superkey 중 최소인 것
(ex) 두 superky {ID}, {ID, name}이 있는 경우, {ID}가 candidate key
primate key
candidate key 중 하나를 primary key로 정의
즉, primate key의 두 가지 조건: 1) tuple을 특정 가능하고 2) null value가 없을 것
foreign key
다른 relation을 참조하기 위한 attribute
Integrity Constraints
entity integrity, referential integrity는 사용자 정의와 별개로 relational model에서 반드시 지켜져야 하는 조건
domain integrity, user-defined integrity는 사용자 정의에 의한 조건
1. entity integrity (개체 무결성)
실제 세계에 있는 개체들을 구분 가능하도록 하는 조건.
primary key는 null값을 가질 수 없음
2. referential integrity (참조 무결성)
relation 간 참조할 때 tuple들의 일관성을 유지하기 위한 조건.
한 relation의 tuple이 다른 relation의 tuple을 참조하고자 한다면 반드시 그 참조되는 tuple이 존재하고 있는 tuple이어야 함
3. domain integrity
attribute의 type에 관한 제한 조건.
attribute가 가질 수 있는 값의 범위, 디폴트값, null값 가능 여부 등
4. user defined integrity
business logic에 근거해 사용자가 지정한 조건.
본 포스트 내용은 고려대학교 컴퓨터학과 "데이터베이스" 강의 내용 일부를 개인 공부 목적으로 정리한 것입니다.
'computer science > 데이터베이스' 카테고리의 다른 글
| Concurrency Control (0) | 2024.01.26 |
|---|---|
| Transaction (0) | 2024.01.25 |
| Relational DBMS (0) | 2024.01.17 |
| Relational Algebra (관계대수) (0) | 2024.01.08 |
| Database Introduction (0) | 2024.01.06 |