본문 바로가기
데이터베이스설계

[데이터베이스설계] 2-6 합집합, 교집합

by 젼젼39 2024. 11. 15.
Union
operation

합집합
Union operation => 릴레이션R 릴레이션S
= 2개의 relation(투플의 집합)들을 결합     //중복 제거됨
 
* r, s가 합집합 연산이 되기 위해 만족해야 하는 조건 [유니온 호환성 union compatibility]
(1) r, s는 동일한 arity(컬럼의 수)을 가져야 한다
(2) 속성 도메인(해당컬럼에 등장가능한 값의 집합=컬럼데이터타입) compatible(호환)되어야 함.
    (: r의 두번째 column s의 두번째 column과 같은 타입이어야 함)
 

Q) find all courses id taught in the Fall 2017 semester, or in the Spring 2018 semester. Or in both
  => π course_id (σ semester=”Fall” ^ year=2017 (section)) ∪ π course_id (σ semester=”Spring” ^ year=2018 (section))
Set-inter
-section
operation

교집합
Set-Intersection operation 교집합 => r s
* 유니온 호환성이 성립되어야 교집합도 성립함
 

Q) find the set of all courses taught in both the Fall 2017 and the Spring 2018 semesters
  => π course_id (σ semester=”Fall” ^ year=2017 (section)) π course_id (σ semester=”Spring” ^ year=2018 (section))