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

[데이터베이스설계] 2-4 Select, Project

by 젼젼39 2024. 11. 13.
SELECT
σ
시그마
SELECT 연산 => σ 조건 (Relation) //시그마 p r                                    [where 부분]
    = 주어진 조건(predicate)를 만족하는 튜플을 선택, relation으로 반환
Q) select those tuples of the instructor relation where the instructor is in the “Physics” department
    => σ dept_name = “Physics” (instructor)

-     
비교연산자 (comparisons) 사용 가능

==> 컬럼 이름 (=, =/=, >, >=, <, <=) value 이렇게도 가능

-      Connectives를 이용해 여러 조건들을 결합해 사용 가능
==> ^(and), v(or), (not)

Q) find the instructors in Physics with a salary greater than $90,000
  => σ dept_name=”Physics” ^ salary>90,000 (instructor)  // σ dept_name=”Physics” and salary>90,000 (instructor)

-     
Select 조건에는 두 속성 간의 비교가 포함될 수 있음

Q) find all departments whose name is the same as their building name
   => σ dept_name=building (department)
Project
π
파이
PROJECT 연산 => π A1,A2,A3…Ak (Relation)             //컬럼들 열거 //열거되지 않은 attribute들을 결과에서 제외
-      겹치는 건 제거함 (결과가 집합이니까)

Q) eliminate the dept_name attribute of instructor
  => π ID, name, salary (instructor)
Select
vs
Project

SELECT σ = 투플을 선택  // PROJECT π = 컬럼을 선택
 
- 관계대수연산의 결과는 relation이므로, 관계대수 연산은 관계대수식으로 함께 구성할 수 있음
 
Q) find the names of all instructors in the Physics department
=> π name (σ dept_name=”Physics” (instructor))
 
- Projection 연산의 argument relation의 이름을 지정하지 않고, relation을 평가하는 표현을 준다