DB rlelational data model
set
서로 다른 elements 를 가지는 collection
순서는 중요하지않다
1 5 9 3 4….
Cartesian product
서로 1개씩 고르는 모든 경우의 수
binary relation
cartesian product 의 부분집합
수학에서의 relation
subset of carteian product
set of tuples
이를 data model에서는 set은 domain을 의미한다
data model 에서의 domain
예시로 설명해보자면
attribute
각각의 도메인들이 이 relation에서 어떤 역할을 수행하는지 이름을 붙여준다
그후 이 도메인에서 하나씩 고르면 그게 tuple이 되고
그걸 table 로 그리면
relational data model
degree of a relation
relation 에서 attributes 의 수
위의 STUDENT 에선 degree 는 6
reaction database schema는
relation schemas set + integrity constraints set로 구성이 된다
relation 의 특징
1. relation 은 중복된 tuple 을 가질수 없다
ex)
1 김가가 010-0000-0000
1 김가가 010-0000-0000
2 김나나 010-0000-0001
이는 중복된게 두개있으므로 불가
null의 의미
값이 존재하지 않는다
값이 존재하나 아직 그값이 무엇인지 알지 못한다
해당사항과 관련이없다
superkey
relation 에서 해당 tuples를 유니크하게 식별할수 있는 attributes set
candidate key (minimal superkey)
어느 한 attribute 라도 제거하면 유니크하게 tuple을 식별할수 없는 superkey
primary key
relation에서 tuple를 유니크하게 식별하기 위해 선택된 candidate key
unique key
primary key 가 아닌 candidate keys
(alternate key)
candidate key 중에서 primary key로 선택안된 나머지를 unique key 라 한다
foreign key
다른 relation 의 PK를 참조하는 attributes set
constraints
relation database의 relations 들이 언제나 항상 지켜줘야하는 제약
implicit constraints
relational data model 자체가 가지는 constraints
ex)
relation 은 중복되는 tuple을 가질수 없다
relation 내에서는 같은 이름의 attribute를 가질수없다
schema-based constraints
주로 DDL 을 통해 schema 에 직업 명시할수 있는 constraints
(explicit constraints)
domain constraints
attribute 의 value 는 해당 attribute의 domain 에 속한 value 여야한다
grade는 1~4학년까지 인데 grade 가 100인건 말이안되므로 위반
key constraints
서로 다른 tuples는 같은 value의 key를 가질수 없다
id 가 key인데 이 id가 같으면 안된다
null value constraint
attribute 가 NOT NULL로 명시됐다면 NULL을 값으로 가질수 없다
entity integrity constraint
PK는 value 에 null이 들어갈수없다
referential integrity constraint
FK와 PK와 도메인이 같아야하고 PK에 없는 value를 FK가 값으로 가질수 없다
team_023이란 팀은 team이란 realtion의 PK로 존재하지 않으므로 위반